Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using compile on an #<Interpreted Closure ??

19 views
Skip to first unread message

Kenneth P. Turvey

unread,
Oct 6, 1998, 3:00:00 AM10/6/98
to
I am trying to convince Allegro Common Lisp to compile a function that
is put together at run-time. I keep getting this error:

Error: Illegal syntax for function:
#<Interpreted Closure (:INTERNAL
(:INTERNAL MAKE-FUZ-COMPLEMENT))
@ #x846c202>

Would someone explain this to me? .. Or just tell me how to compile
it?

Thanks,

--
Kenneth P. Turvey <ktu...@pug1.SprocketShop.com>

The only two things that are infinite in size are the universe and human
stupidity. And I'm not completely sure about the universe.
-- Albert Einstein

Kent M Pitman

unread,
Oct 7, 1998, 3:00:00 AM10/7/98
to
ktu...@www.sprocketshop.com (Kenneth P. Turvey) writes:

> I am trying to convince Allegro Common Lisp to compile a function that
> is put together at run-time. I keep getting this error:
>
> Error: Illegal syntax for function:
> #<Interpreted Closure (:INTERNAL
> (:INTERNAL MAKE-FUZ-COMPLEMENT))
> @ #x846c202>
>
> Would someone explain this to me? .. Or just tell me how to compile
> it?

CLHS (in the exceptional situations for COMPILE) says: 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. I can't speak for sure to
Allegro, but LispWorks has a similar limitation to the one you're
observing, and usually the mention of a "closure" means the lexical
environment contained a free reference to an outer let binding or
function argument binding. That is, your code is likely what's in error.

Try compiling the function that makes it and then calling that function
RATHER THAN calling the function that makes it and compiling the result,
which you appear to be doing.

That is, rather than
(defun foo (x) #'(lambda () x))
(compile nil (foo 3))
try:
(compile (defun foo (x) #'(lambda () x)))
(foo 3)

(I didn't test this.)

Erik Naggum

unread,
Oct 7, 1998, 3:00:00 AM10/7/98
to
* ktu...@www.sprocketshop.com (Kenneth P. Turvey)

| I am trying to convince Allegro Common Lisp to compile a function that
| is put together at run-time.

you didn't say which version of Allegro Common Lisp, nor did you show us
what you tried to do, yet both are necessary to understand your problem.
nonetheless, I can guess: your ACL version is 4.3.1 or earlier, and you
attempt to do the equivalent of

(compile nil #'(lambda (...) ...))

which fails in ACL 4.3 and 4.3.1, and probably also in earlier releases.
the following advise will make COMPILE in ACL 4.3.1 (and probably in
earlier releases, as well) accept interpreted functions as the second
argument, which ACL 5.0 accepts:

(advise compile :before compile-interpreted-functions nil
(when (interpreted-function-p (second arglist))
(setf (second arglist) (excl::func_code (second arglist)))))

note that this will _still_ fail on closures. it also appears that no
matter whether there are references to bindings in the closed-over
environment, ACL 5.0 will also create a closure object, making it
impossible to compile any internal functions this way to begin with.

(note: similar advice is needed for DISASSEMBLE in both 4.3.1 and 5.0, to
accept interpreted functions as arguments.)

however, compiling the containing function always also compiles internal
functions, so this situation seems impossible in the first place.

now, I have to assume you do something really weird, like calling COMPILE
on a function object that would already have been compiled in a compiled
function, but which fails in a uncompiled function. in that case, just
omit the inner call to COMPILE, and compile the containing function.

if you really want to construct a new function that does not reference
any closed-over bindings, only their values at compile time, you _could_
do something like this:

(compile nil `(lambda (...) ... ,whatever ...))

where WHATEVER is whatever variable whose value you want to be constant
in the code.

well, all this is without knowing what you try to do or how you do it,
but I hope it provides some leads.

#:Erik

0 new messages