emacs-devel
[Top][All Lists]
Advanced

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

Re: [Emacs-diffs] trunk r116995: cl-lib defstruct introspection


From: Stefan Monnier
Subject: Re: [Emacs-diffs] trunk r116995: cl-lib defstruct introspection
Date: Mon, 21 Apr 2014 23:28:09 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> Something like this. (This is the private code I was talking about, so
> it doesn't use the sames in the checked-in patch.)

> (defmacro* jez-with-slots (spec-list (type inst) &body body)
>   "Like `with-slots', but for structs."
>   (if (symbolp inst)
>       `(symbol-macrolet
>            ,(loop for spec in spec-list
>                   collect `(,spec (jez-slot-value ',type ,inst ',spec)))
>          ,@body)
>     (let ((inst-symbol (gensym "with-struct-slots")))
>       `(let ((,inst-symbol ,inst))
>          (jez-with-slots
>              ,spec-list ,inst-symbol ,@body)))))

Ah, I see now, thanks, yes that makes sense.


        Stefan


PS: Of course, I wouldn't implement it that way ;-)
I'd start by testing `inst' against `type' and then use straight (aref
...)  or (nth ...) for the accessors.
But indeed, you'd want to circumvent the usual accessors.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]