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

Re: Are nested DEFUN's illegal?



Mark Thomas <thommark@access.digex.net> noticed the following:

> > (defun bar (x)
>     (defun foo ()
>       (+ x 3)))
> *** - THE-ENVIRONMENT is impossible in compiled code

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

> Note 1:  Perhaps nested DEFUN forms are considered poor style, but is
> 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
                    haible@ma2s2.mathematik.uni-karlsruhe.de