Scheme Semantics: Introduction | Print Statement | Declaration/Assignment Statements | Let Statement | Lambda Statement | Define Statement | If Statement
Remainder of this Paper: Scheme Introduction | Lexer | Parser | Continuations

Scheme If Statement


An example of an If Statement:


(define n -5)

(if (< n 0)
      (- 0 n)
      n)		=> 5

Semantic structure, assuming that n is already defined:
Env_0
I/O_0

( if (
	Env_00
	expr_01
	Val_01
	Env_01 = Env_00 + (Val_0)
	)(
	expr_02			;if Val_01 is evaluated to true, or a number greater than zero, this three-line branch is evaluated 
	Val_02			;Val_02 is created
	Return: Val_02	;Val_02 is returned to the toplevel scope for output
	)
	expr_03			;if Val_01 is evaluated to false, or a number less than zero, this three-line branch is evaluated
	Val_03			;Val_03 is created
	Return: Val_03	;Val_03 is returned to the toplevel scope for output
	)
Env_0				;the environment doesn't change because there are no new bindings or variables created that it can see
					;nor have there been changes to any existing bindings
I/O_1 = I/O_0 + (if Val_01, then terminal_output:Val_02, else terminal_output:Val_03)