Re: Equivalent of C's "global/static" variables
- From: Brian Downing <see-signature@xxxxxxxxx>
- Date: Tue, 17 Jan 2006 18:34:24 GMT
Duane,
Very informative, thanks! A few points:
In article <o07j8yohqs.fsf@xxxxxxxxx>, Duane Rettig <duane@xxxxxxxxx> wrote:
> > CMUCL at least says
> > "#<Interpreted Function UPDATE {480245C1}> was defined in a non-null
> > environment."
>
> This message, however, suggests a bug in CMUCL - whereas is perfectly
> reasonable to decide not to compile the lexical closure for update in
> the particular non-null lexical environment it was given, the spec
> is more careful about how it states where the undefined behavior starts
> and ends; what it actually says, in teh descriptuon for COMPILE, is:
>
> "The consequences are undefined if the lexical environment
> surrounding the function to be compiled contains any bindings
> other than those for macros, symbol macros, or declarations."
>
> So in fact, something like:
>
> (macrolet ((foo (x) `(car ,x)))
> (defun bar (y) (foo y)))
>
> ...
>
> (compile 'bar)
>
> should in fact work. Perhaps they've fixed it now, but the versions
> of cmucl I try out from time to time don't handle this; apparently
> they refuse to compile any interpreted function within a non-null
> lexical environment (which is not what the spec allows). Perhaps
> there should have been a glossary term such as "trivial lexical
> environment" to cover a lexical environment which is non-null, but
> has no lexical definitons other than macros, symbol-macros, or
> declarations - then an error message like "... was defined in a
> non-trivial lexical environment." would have been an easy and well-defined
> error message...
Agreed, and I think I got this right in SBCL's evaluator (due to be
finished and integrated into mainline well before the year 2038):
* (macrolet ((foo (x) `(car ,x)))
(defun bar (y) (foo y)))
BAR
* (compile 'bar)
BAR
NIL
NIL
* (let ((x 4))
(defun set-x (v) (setf x v))
(defun get-x () x))
GET-X
* (compile 'get-x)
debugger invoked on a SB-EVAL::ENVIRONMENT-TOO-COMPLEX-ERROR in thread 313:
Lexical environment of #<INTERPRETED-FUNCTION GET-X> is too complex to
compile.
> [*] Compilation of definitions within the original form clearly has
> undefined consequences, so this part of the discussion deals with
> parts over and above the spec. I agree that the error message that
> Allegro CL gives is not helpful. However, if there had not been a
> bug in the way Allegro CL extends the spec to try to make some sense
> out of calling compile on these definitions, then you would not have
> gotten any error at all, but would have instead gotten a compiled
> functon which would have done the intuitively correct thing. We're
> able to consider doing this because of the similarity between the
> representations of compiled and interpreted environments in our
> implementation.
> It is unfortunate that you selected 'update to compile, since that
> one demonstrates the bug. The bug is that we rewrite the accesses
> to each variable as locally forms, and they do not expand well
> in setf situations. I will be working on fixing that, probably for
> future releases, but fortunately I can show you how it _does_ work
> in situations where setf is not involved, and in fact the code
> is already provided (we just compile the other function!):
I must say I'm very impressed you can make this work even some of the
time! Thinking about how to make this work in the above SBCL evaluator
generally gave me a headache, and after seeing every other implementation
I tried not do it either (and reading in the spec that it's undefined),
I decided to punt. It's doubly unfortunate that in all the cases I've
tried it on ACL I've stumbled across this bug.
-bcd
--
*** Brian Downing <bdowning at lavos dot net>
.
- Follow-Ups:
- Re: Equivalent of C's "global/static" variables
- From: Duane Rettig
- Re: Equivalent of C's "global/static" variables
- References:
- Equivalent of C's "global/static" variables
- From: bradb
- Re: Equivalent of C's "global/static" variables
- From: Brian Downing
- Re: Equivalent of C's "global/static" variables
- From: Duane Rettig
- Equivalent of C's "global/static" variables
- Prev by Date: Re: Why no compiler-macrolet?
- Next by Date: Re: Lisp is Sin
- Previous by thread: Re: Equivalent of C's "global/static" variables
- Next by thread: Re: Equivalent of C's "global/static" variables
- Index(es):
Relevant Pages
|