logo       

Re: New, from-scratch implementation of backquote.: msg#00077

lisp.clisp.general

Subject: Re: New, from-scratch implementation of backquote.

Kaz Kylheku <kaz@xxxxxxxxxxxxxxxxxxx> writes:

> On 11 Apr 2003, Todd Sabin wrote:
>
> > Perhaps it's obvious, but the last message was unfinished; I never
> > noticed how close C-c C-c is to C-x C-x before :\
> >
> > Anyway, the code I sent doesn't do what I thought it did, so just ignore
> > me for now... :)
>
> Yep. It returns the list (defclass ...) which still needs to be EVAL-ed.
>
> You can't fix this, because you can't get around the fact that defclass
> is a compile-time construct.
>
> To define a new class at run-time, you need to construct a new instance
> of the defclass syntax, and to activate it, you must either EVAL it,
> or put it in a lambda body and COMPILE it, and then funcall the
> resulting object.

Right, I was just about to send corrected code identical to the extra
crispy below...

> The other alternative would be to use the underlying ENSURE-CLASS
> function, but that is not portable, (except where the MOP is
> implemented)?
>
> So we can repair your function by moving the backquote out to the whole
> lambda, and then by using the COMPILE function---which is probably kind
> of a waste of cycles just to run defclass once. ;)

That's interesting. I guess I've been prejudiced against eval so much
by all the "you almost never really need eval" stuff around that I
always avoid it if there's an alternative. But this does seem to be a
perfectly good use for it. Thanks.

> ;; original recipe
> (defun defclass* (name supers slots &rest options)
> (funcall (lambda ()
> `(defclass ,name ,supers ,slots ,@options))))
>
> ;; extra crispy
> (defun defclass* (name supers slots &rest options)
> (funcall (compile nil
> `(lambda ()
> (defclass ,name ,supers ,slots ,@options)))))
>
> ;; calorie reduced
> (defun defclass* (name supers slots &rest options)
> (eval `(defclass ,name ,supers ,slots ,@options)))

I'd still like to see a real-world application of the original
macrolet examples, if anyone knows one. When I first read that stuff
I had the feeling of a light bulb going on somewhere, but I haven't
figured out where it is or what it's illuminating, yet...


Todd


-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise