Confused about compiling and closures...
Hi,I have run into a brick wall on several occasions regarding the compiler complaining about trying to compile a closure...
To whit: if I enter the following into the text editor:
(defun plus (a b)
(+ a b))
(let ((plus #'plus))
(defun plus3 (x)
(funcall plus 3 x))))
(defun plus (a b)
(* a b))
The first definition of plus is the one I want to capture. I produce the function plus3. Then I redefine plus so that I can check that the behavior of plus3 remains unchanged. It does, and so far so good. If I hadn't first captured the existing definition of #'plus by means of the surrounding LET, then the later redefinition of plus would have altered the meaning of plus3.
If I compile the region in the text editor containing this text, or even save it to a file and do compile & load, I get no errors. A warning is issued that plus is defined more than once. Okay.
But if I evaluate the definition of plus3 with Alt-Ctl-X in the editor, or just type it into the listener, I get an interpreted closure, not a compiled one. Attempting to compile this result manually with
(compile 'plus3)
produces the error:
Error: #<interpreted function PLUS3 200D13F2> is a lexical closure.
There have been other times at which I inadvertently produced some kind of closures and the LW system refused to save as a FASL file. The CLTL2 states that this refusal is permissible behavior. The same code has been accepted and saved as a FASL file by Allegro in the past. So implementations vary in this treatment.
Under what conditions can a closure be produced as compiled code? Is it always subject to implementation variances?
David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ 85750