Lisp HUG Maillist Archive

compiling anonymous function

I have a function  #<anonymous interpreted function 2E53A15A> bound to a 
variable f and hence I can call  it: (funcall  f  ....)
However, I can't compile it, because (compile f) complains that f is not 
a symbol and (compile 'f) says that f is  an undefined function, which 
is of course right. Is there  nevertheless a way to  compile f?
Yours,
Reinhard Oldenburg
 


Re: compiling anonymous function


On 7 Oct 2008, at 21:05, Reinhard Oldenburg wrote:

>
> I have a function  #<anonymous interpreted function 2E53A15A> bound  
> to a variable f and hence I can call  it: (funcall  f  ....)
> However, I can't compile it, because (compile f) complains that f is  
> not a symbol and (compile 'f) says that f is  an undefined function,  
> which is of course right. Is there  nevertheless a way to  compile f?
> Yours,
> Reinhard Oldenburg

(setf f (compile nil f)) should do the trick.


Pascal

-- 
Lisp50: http://www.lisp50.org

Pascal Costanza, mailto:pc@p-cos.net, http://p-cos.net
Vrije Universiteit Brussel, Programming Technology Lab
Pleinlaan 2, B-1050 Brussel, Belgium








Re: compiling anonymous function


Reinhard Oldenburg wrote:
>
> I have a function  #<anonymous interpreted function 2E53A15A> bound to 
> a variable f and hence I can call  it: (funcall  f  ....)
> However, I can't compile it, because (compile f) complains that f is 
> not a symbol and (compile 'f) says that f is  an undefined function, 
> which is of course right. Is there  nevertheless a way to  compile f?
> Yours,
> Reinhard Oldenburg

(compile nil f)

Mitch


Re: compiling anonymous function

On Tue, Oct 07, 2008 at 09:05:56PM +0200, Reinhard Oldenburg wrote:
> I have a function #<anonymous interpreted function 2E53A15A> bound
> to a variable f and hence I can call it: (funcall f ....)
> However, I can't compile it, because (compile f) complains that f is
> not a symbol and (compile 'f) says that f is an undefined function,
> which is of course right. Is there nevertheless a way to compile f?

Not directly.  You must compile whatever generated f.

  CL-USER 4 > (defun make-closure () (lambda () 'foo))
  MAKE-CLOSURE

  CL-USER 5 > (make-closure)
  #<anonymous interpreted function 2295B052>

  CL-USER 6 > (funcall *)
  FOO

  CL-USER 7 > (compile 'make-closure)
  MAKE-CLOSURE
  NIL
  NIL

  CL-USER 8 > (make-closure)
  #<Function (MAKE-CLOSURE . 1) 22A63A7A>

  CL-USER 9 > (funcall *)
  FOO

Note that MAKE-CLOSURE only makes compiled closures AFTER you compile
it.  If you make and store a closure BEFORE you compile MAKE-CLOSURE,
they don't change just because you compiled MAKE-CLOSURE at some later
time.

Hope that helps.

-- L


Updated at: 2020-12-10 08:42 UTC