Static Properties

    The LET special form

(let ((var1 exp1)
      (var2 exp2)
      ...

      (varn expn))
 body)

The region associated with var1..varn is body
sequence:
	exp1 evaluated
	exp2 evaluated

	expn evaluated
binding to 
	var1, ... , varn

then body is evaluated with this binding.

Let returns whatever body returns


precisely equivalent to:

((lambda (var1 var2 ... varn) body)
 exp1 exp2 ... expn)


Scheme compilers immediately translate a let
expression to the corresponding lambda expression 





Static Properties of Variables

Those properties that can be determined by
analyzing the TEXT of a program are STATIC

DYNAMIC properties are determined at run-time. 

STATIC properties can be analyzed by a compiler
	detect errors
	optimization

In most languages (including scheme), the relation
between a variable reference and the formal
parameter to which it refers is static




FREE and BOUND Variables

Simplest context:

Consider a LANGUAGE that only has

	1. variable references
	2. Lambda expressions with a single formal 
	   parameter
	3. procedure calls


exp  ::== varref
	| (lambda (var) exp )
	| (exp exp)

This is the LAMBDA CALCULUS language:



BOUND variable

A variable reference in an expression is BOUND
if it refers to a formal parameter introduced in
that expression

((lambda (x) x) y)

The reference to x is BOUND

FREE variable

If a variable is not bound it is FREE

((lambda (x) x) y)

The reference to y is FREE




A variable is said to OCCUR BOUND in an expression
if the expression contains a bound reference to
the variable. Similarly, a variable is said to
OCCUR FREE if the expression contains a free
reference to the variable


ALL variable references must have some associated
values when they are evaluated. OTHERWISE there
will be an ERROR during evaluation.

If 
	a variable reference is bound to a formal
	parameter it is LEXICALLY BOUND.
ELSE
	They must be bound at the top level (by
	definition)  OR
	be supplied by the system.
	GLOBALLY BOUND

-----

ERROR if they are not lexically or globally bound.
	


The value of an expression ONLY depends on the
values associated with variables that occur free
within the expression.
The CONTEXT that surrounds the expression must
provide the value of the free variable

((lambda (x) x) y)

y is FREE

For example, consider the context provided by: 

(lambda (y) 
  ((lambda (x) x) y)
  )

provides a value for y

Thus a variable that occurs free in one contex can 
be bound in a larger surrounding context.

Suppose x has some associated value (say foo)

the value of ((lambda (x) x) y)

is independent of x's old value (foo) because 
x will be bound to y's value.



The meaning of
	(lambda (x) x) 
is always the same -- it is the identity
function. The meaning is always the same,
independant of everything/anything else
because there are no free variable refs in 
	(lambda (x) x)

Thus an expression's meaning only depends on
variable refs that occur free.

Other lambda expressions without free variables
also have FIXED meanings

(lambda (f)
   (lambda (x)
     (f x)))

is a procedure that takes a procedure f 
and returns a procedure that takes 
a value x, applies f to it, and returns the
result.


lambda expressions without free variables are
called COMBINATORSXS

Identity combinator
Application combinator 

are useful combinator tools



FORMAL:

A variable x occurs free in an expression E if and 
only if

1.E is a variable reference and E is the same as x; 
OR
2.E is of the form (E1 E2) and x occurs free in E1 
or E2
OR
3. E is of the form (lambda (y) E'), where y is
different from x and x occurs free in E'




A variable x occurs bound in an expression E if and 
only if

1.E is of the form (E1 E2) and x occurs bound in
E1 or E2
OR
2.E is of the form (lambda (y) E'), where x occurs
bound in E' or x and y are the same variable

3. No variable occurs bound in an expression
consisting of just a single variable.



Example of a lambda calculus expression where
a variable occurs free and bound
((lambda (y) y) y)

Example of a lambda calculus expression where
a variable occurs free but which has a value that
is independant of the free variable's value

((lambda (x) 1) y)

    

Sushil Louis
Last modified: Mon Sep 20 11:24:46 PDT 1999