Re: Q: Compiling closure to file
The problem is a general CL issue - function literals can't be dumped to
file.
The way your code is set up, the %make-closure function returns a
function literal which, ultimately, is embedded in the function test.
The following revision to %make-closure works since the macro returns
the function-creating form rather than the function itself.
(defun %make-closure (x)
`(let (y)
(lambda ()
(unless y (setq y (* ,x 1000))) ; long run
(1+ y))))
Hope this helps.
Regards
Guy.
In message <000001c39df3$3552d2e0$425702c3@digo>, Dmitri Ivanov
<divanov@aha.ru> writes
>Hello lispworkers,
>
>I have the following piece of code in the file cc.lisp:
>----------------
>(defun %make-closure (x &aux y)
> (lambda ()
> (unless y (setq y (* x 1000))) ; long run
> (1+ y)))
>
>(defmacro cc (x)
> `(funcall ,(%make-closure x)))
>
>(defun test ()
> (+ (cc 2) (cc 3)))
>
>(cc 3)
>(test)
>----------------
>When compiling this file with LWW 4.3, I have got the following:
>
>**++++ Error in TEST:
> Object #<interpreted closure (LAMBDA NIL (UNLESS Y (SETQ Y (* X 1000)))
>(1+ Y))> is of type TYPE::INTERPRETED-FUNCTION which is not externalizable
>to #<STREAM::LATIN-1-FILE-STREAM E:\Lisp\Projects\t_cc.fsl>.
> (TOP-LEVEL-FORM 2)
> *** 1 error detected, no fasl file produced.
>;; Compilation finished with 0 warnings, 1 error.
>
>Is this a LW-specific problem or general CL issue?
>
>The workaround could be not to compile the TEST function at all, but put
>into a separate file and load from the .lisp source instead of .fasl.
>However, leaving the function interpreted means macroexpansion occurring
>every time it gets called, which is undermines the usefulness of the
>closure.
>Any takers?
>
>BTW, is it possible to declare some function interpreted within the body of
>the file being compiled?
>--
>Sincerely,
>Dmitri Ivanov
>www.ystok.ru
>
--