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

Re: Multiple LAMBDA evaluations



>From JINX:

  > We should certainly not require that both evaluations return EQ?
  > objects.

I'm more concerned about whether I am ALLOWED to return values that
are EQ?, not that I might be REQUIRED to.

  > Note: Is it true that the only way that a lambda expression can be
  > re-evaluated in the same environment is by using
  > call-with-current-continuation?

No.  Consider the following...

(define foo
  (lambda (msg)
    (case msg
      ...
      ((XXX) (lambda (args) do-something))
      ...)))

Here, FOO returns a closure every time it is called with argument XXX.
I expect that most implementations would ``cons up'' a new closure
object every time.  The following code does the same thing, but the
closures returned are always EQ? to each other.

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

My motivation is to allow an optimizing compiler to map code like the
first into code like the second.  This is related to the traditional
compiler optimization which moves invariant computations out of loops.

Here's another example:

(define bar
  (lambda (x)
    (map (lambda (y) (+ y 13))
	 x)))

I would like to transform this into...

(define bar
  (let ((temp (lambda (y)(+ y 13))))
    (lambda (x)
      (map temp x))))

Regards,
David Bartley
-------