[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compiling interpreted functions

I'm having a problem storing functions in structures, and I hope
someone can help clarify this for me.  The problem exists in
both  Franz Allegro and Macintosh Common Lisp so I'm sure the
problem is with my understanding rather than a particular

I've defined a simple structure and macro to illustrate the problem:

(defstruct r fun)
(defmacro macro(X) `(defparameter ,x (make-r :fun #'(lambda() ',x))))

Now, if I compile a file that has a call to the macro:
(macro one)

and load the file , everything works fine, as one would expect:
USER(9): (r-fun one)
#<Function (:INTERNAL (:TOP-LEVEL-FORM "simple" 2) 0) @ #x6e1fe6>
USER(10): (compiled-function-p (r-fun one))
USER(11): (macroexpand '(macro one))
USER(12): (funcall (r-fun one))


If the form is entered at top level to lisp, everything
works fine also:


USER(14): (macro two)
USER(15): (funcall (r-fun two))
USER(16): (compiled-function-p (r-fun two)) 
USER(17): (r-fun two)
#<Interpreted Function (unnamed) @ #x6e9cee>


However, as 16 points out, this isn't compiled, so I'd like
to compile it.  However, I can't figure out how to compile it:

USER(18): (setf (r-fun two) (compile nil (r-fun two)))
Error: Illegal syntax for function: #<Interpreted Function (unnamed) @ #x6e9cee>

A little experimentation (and reading the manual) shows:
USER(19): (compile nil '(lambda(x) x))
#<Function (:ANONYMOUS-LAMBDA 0) @ #x65151e>
USER(20): (compile nil #'(lambda(x)x))
Error: Illegal syntax for function: #<Interpreted Function (unnamed) @ #x654c4e>


So, the question is:
How does one compile a lambda expression? [I'd like a solution that
works in all Common Lisps if possible].

By the way, this is an extreme simplification of the real problem I'm
trying to address in which the functions to be compiled are "logic
programs." These logic programs can be defined in a file, or can be
created by a machine learning program, and I'd like them all to be


Michael Pazzani
Department of Information and Computer Science
University of California
Irvine, CA 92717-3425
phone (714) 856-5888
fax   (714) 856-4056
e-mail pazzani@ics.uci.edu