[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple LAMBDA evaluations



  > Your counter examples do not disprove my claim.  In all cases no
  > lambda expression is evaluated twice in the same environment.
  > [...]  I guess that the difference is that I view environments as
  > objects (probably influneced because of our dialect), and
  > conceptually a new one is created every time a lambda expression
  > is applied, even if this lambda expression has no bindings.

Sorry, I've tripped up on another assumption that needs to be
discussed!  In my first example (reproduced below), I assumed that the
DO-SOMETHING in the body of the inner lambda was an expression that
did not reference MSG.  Thus, in a pragmatic sense, it didn't have to
be closed over that part of the environment.  This is the analysis
that permits a compiler to transform

	(define foo
	  (lambda (msg)
	    (case msg
	      ...
	      ((XXX) (lambda (args) do-something))
	      ...)))
into
	(define foo
	  (let ((xxx-handler  (lambda (args) do-something)))
	    (lambda (msg)
	      (case msg
		...
		((XXX) xxx-handler)
		...))))

since I'm moving the lambda relative to its environment.

So, I agree with your point, but I'm shifting the question a bit: Is
there a consensus that these kinds of optimizations are permitted?

To my knowledge, the only way to know whether a procedure object has
closed over the entire ``visible'' environment or just the part of it
which it references is to have something like MIT Scheme's
PROCEDURE-ENVIRONMENT.  This function returns the environment over
which a procedure was closed.  Our implementation of Scheme supports
first-class environments in the MIT sense and has this function, but
we consider it a debugging tool only, and do not guarantee that it
returns the entire environment unless the compilation took place in
``debug mode.''

So, I consider the environment closed over to be an abstraction with
different implementations possible.  Thus, if the environments may or
may not be EQ?, the closures may or may not be EQ?.

Regards,
David Bartley
-------