From: Barry Margolin
Subject: Re: Compiling lexical closures in Common Lisp
Date: 
Message-ID: <37631@think.Think.COM>
In most Lisps, the format of environments used by interpreted and compiled
closures are different (interpreted environments are usually a list of
association lists, while compiled environments are usually arrays).  All
the lexical closures that come from the same environment must be compatible
with the environment.  Suppose you were to write:

(let ((x 0))
  (setf (symbol-function 'counter-value)
	#'(lambda () x))
  (setf (symbol-function 'increment-counter)
	#'(lambda () (incf counter))))

(compile 'counter-value)

This would presumably want to convert the lexical environment in the
closure to the compiled form, but this would cause problems for
INCREMENT-COUNTER, which expects its environment to be in the other format.

The file compiler doesn't have this problem because it is always compiling
all the functions that share a lexical environment.

I think ANSI CL will require that you be able to call COMPILE on all
functions.  However, in cases such as the above it may be implemented as a
no-op (in fact, CLtL doesn't require the compiler to do anything, it merely
suggests that compiled functions are likely to run faster).
--
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar