Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: How must we teach lexical scope?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: oleg@p...
Subject: Re: How must we teach lexical scope?

Loup Vaillant wrote:
> Personally, I think environments are about the implementation of
> lexical scope, not  its specifications.

I agree. A language system that eagerly performs substitutions
inherent in the beta-rule needs no environments. An environment, which
is a list of pending substitutions, is merely an optimization. A quite
good optimization though. This is discussed in an article

	http://okmij.org/ftp/Scheme/misc.html#closure-misconceptions

Regarding free variables: some of the multi-staged languages,
including MetaOCaml, can literally manipulate code with `free
variables'. For example,

      let bar u = print_endline "here"; .<.~u + 1>. in
      .<fun x -> .~(bar .<x+3>.)>.;;

Evaluating this code prints the string "here" and returns a code
value, which can be printed as .<fun x_1 -> ((x_1 + 3) + 1)>.
We note that the function bar received a piece of code .<x+3>.
containing a free variable 'x' and incorporated that piece of code 
in the larger code. All while the binding for "x", "fun x -> ..." will
be evaluated only in the future.