Next: scheme overview forms, Previous: scheme overview variables, Up: scheme overview [Index]
The variables bound by a let expression are local, because
their bindings are visible only in let’s body. Scheme also
allows creating top–level bindings for identifiers as follows:
(define x 23) (define y 42) (+ x y) ⇒ 65
these are actually “top–level” in the body of a top–level program or library. Libraries.
The first two parenthesized structures are definitions; they create top–level bindings, binding ‘x’ to ‘23’ and ‘y’ to ‘42’. Definitions are not expressions, and cannot appear in all places where an expression can occur. Moreover, a definition has no value.
Bindings follow the lexical structure of the program: When several bindings with the same name exist, a variable refers to the binding that is “closest” to it, starting with its occurrence in the program and going from inside to outside, and referring to a top–level binding if no local binding can be found along the way:
(define x 23)
(define y 42)
(let ((y 43))
(+ x y)) ⇒ 66
(let ((y 43))
(let ((y 44))
(+ x y))) ⇒ 67