Subject: Are nested DEFUN's illegal?

From: "M. Thomas" <[email-masked]>
Date: Tue, 6 Dec 1994 14:15:41 -0500 (EST)

Watch what happens when I type a nested DEFUN form into the CLISP
interpreter (version "1994-10-26 (October 1994)"):

> (defun bar (x)
    (defun foo ()
      (+ x 3)))

*** - THE-ENVIRONMENT is impossible in compiled code

Does this mean that nested DEFUN forms are illegal?  There seems to be no
discussion of this in CLtL2, but on page 92, Steele uses the form above as
an example. 

Note 1:  Perhaps nested DEFUN forms are considered poor style, but is
there a _technical_ reason for disallowing them?  (Naturally, I was able 
to achieve the effect I wanted by creating and passing closures ...)

Note 2:  I believe the 1994-7-4 version of CLISP didn't complain about 
nested DEFUN forms.

Note 3:  The error message refers to 'compiled code'.  What code is that?

Thanks for satisfying my curiosity.

Mark A. Thomas
[email-masked]

---

From: haible (Bruno Haible)
Date: Thu, 8 Dec 94 16:22:56 +0100

> *** - THE-ENVIRONMENT is impossible in compiled code

This is a bug. It will be fixed in the next release.

> there a _technical_ reason for disallowing them?

There is no technical reason for disallowing them. Nested DEFUNs are simply
used so rarely that it wasn't noticed before you came.

> The error message refers to 'compiled code'.  What code is that?

When the "defun bar" is evaluated, the macros inside of it are expanded. This
is a kind of pre-compilation. The "defun foo" wants to save its form and
environment, in order to make it possible to later (ED 'FOO). I put in an
error message because this is not possible if BAR were compiled. But - and
that's the bug - it is not compilation, but only pre-compilation which
happens here.

                    Bruno Haible
                    [email-masked]