Static Properties of Variables
Code for free-vars and bound-vars
The Cond special form:
performs a multiway branch based on series of test
expressions.
(cond
[test1 consequent1]
[test2 consequent2]
[test3 consequent3]
...
...
[testn consequentn]
[else alternative])
OR
(cond
(test1 consequent1)
(test2 consequent2)
(test3 consequent3)
...
...
(testn consequentn)
(else alternative))
else is a keyword.
Test expressions are evaluated in the order in which
they occur until one returns true. The associated
consequent expression is then evaluated.
If none of the test expressions are true, the
alternative expression is evaluated.
cond expressions are equivalent to nested if
expressions.
(if test1
consequent1
(if test2
consequent2
....
(if testn
consequentn
alternative) ... ))
Scope and Lexical Address:
Each declaration of a variable has a region of text
where that declaration is effective
In scheme, the region of effectiveness of a formal
parameter is the body of the lambda expression.
The SCOPE of a variable declaration is the text within
which references to the variable refer to the
declaration.
> (lambda (x x) ... ) is ILLEGAL
In most languages, a variables region and scope can be
determined statically.
Scheme/C/C++
Lexically/Statically scoped languages == Block
structured languages
> (define x
(lambda (x)
(map (lambda (x) (+ x 1)) x)))
Inner declaration creates hole is the scope of the
outer one. Region != scope
The inner declaration shadows outer declarations
The declaration of a variable v has a scope that
includes all references to v that OCCUR FREE in the
region associated with v.
Those references to v that OCCUR BOUND in the region
associated with v's declaration are shadowed by inner
declarations.
----
Simple algorithm for finding which declaration
is associated with a variable reference
Search outward for declaration from variable reference
region. First one found is the associated declaration.
If none found even at topmost (global) level then ERROR.
(lambda (x)
(lambda (y)
((lambda (x)
(x y))
x)))
(lambda (z)
((lambda (a b c)
(a (lambda (a) (+ a c)) b))
(lambda (f x)
(f (z x)))))
-------
Wed: Finish reading chapter 2.
Sushil Louis
Last modified: Mon Sep 27 11:19:51 PDT 1999