Thursday, March 10, 2005

Perlis: Lexical Scope

Alan Perlis on lexical scope:
One man's constant is another man's variable.

Making something variable is easy. Controlling duration of constancy is the trick.

As Will Rogers would have said, "There is no such thing as a free variable."
I remember trying to understand this very idea in high school calculus, but my teacher had no idea what I was getting at. Who knew all I needed was the lambda calculus?

There is no difference between a variable and a constant except the lexical context in which you are looking at it. In this function:
(lambda (n)
(+ n k))
the variable k is a constant, right?
(define (make-adder k)
(lambda (n)
(+ n k)))

No comments: