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 Let Statement


This doesn't work; the language requires that there be an expression associated with a let.


(let ((x 2)))
This doesn't work either; x is not considered an expr on its own. expr = (op id/num id/num)

(let ((x ))(x))
2 is bound to the id x, then the expression (+ x 3) is evaluated, substituting 2 for x

(let ((x 2))
	(+ x 3))
The semantic structure of the let is as follows:
Env_0
I/O_0

(let 
	Env_00
	brown((Var
	Env_01 = Env_00 + (Var)		;the identifier Var is added to the let's environment
	expr_01
	Val_00
	Env_02 = Env_01 + (Var:=Val_00)		;Val_00, the evaluated result of expr, is bound to Var
	Env_01
	)...)
	(expr_02
	Val_01
	Return: Val_01
)
)
I/O_1 = I/O_0 + (terminal_output:Val_01)
Env_0				;toplevel environment doesn't change because nothing identifiers added
				;or binding changed are visible outside the let block

Nested let - only indentifier-value bindings bound in inner let can be seen by the associated expressions. the inner bindings shadow the outer bindings, but this can be avoided by simply using different identifiers for variables.

(let ((a 4) (b 3))
	(let ((a (* a a)) 
	      (b (* b b)))
	   (+ a b)))