Buy GNU books!
|[ < ]||[ > ]||[ << ]||[ Up ]||[ >> ]||[Top]||[Contents]||[Index]||[ ? ]|
define form which appears inside the body of a
letrec or equivalent expression is
called an internal definition. An internal definition differs
from a top level definition (see section 25.1 Top Level Variable Definitions), because the definition
is only visible inside the complete body of the enclosing form. Let us
examine the following example.
(let ((frumble "froz")) (define banana (lambda () (apple 'peach))) (define apple (lambda (x) x)) (banana)) => peach
Here the enclosing form is a
let, so the
defines in the
let-body are internal definitions. Because the scope of the
internal definitions is the complete body of the
lambda-expression which gets bound
to the variable
banana may refer to the variable
even though it's definition appears lexically after the definition
banana. This is because a sequence of internal definition
acts as if it were a
(let () (define a 1) (define b 2) (+ a b))
is equivalent to
(let () (letrec ((a 1) (b 2)) (+ a b)))
Another noteworthy difference to top level definitions is that within
one group of internal definitions all variable names must be distinct.
That means where on the top level a second define for a given variable
acts like a
set!, an exception is thrown for internal definitions
with duplicate bindings.
|webmaster||delorie software privacy|
|Copyright © 2003 by The Free Software Foundation||Updated Jun 2003|