[pro] The Best Examples of "Code is Data"

Yakov Zaytsev zaytsev.yakov at gmail.com
Sun Sep 5 18:56:38 UTC 2010


My best macro so far ;-)

(defmacro access-slot (object &rest slot-names)
  `(ff:fslot-value-typed (ff:foreign-pointer-type ,object)
                         :c (ff:foreign-pointer-address ,object)
                         , at slot-names))

(defmacro define-struct-getter (struct package &rest slots)
  (loop for s in slots
     do (let ((acc (intern (concatenate 'string (symbol-name struct) "-"
(symbol-name s))))
                   (sp (intern s package)))
               (eval `(defmacro ,acc (object)
                        `(access-slot ,object ',',sp))))))

because it is a macro which writes macros which uses macro. My first real
world macro.

On Sun, Sep 5, 2010 at 4:24 PM, Kazimir Majorinc <kazimir at chem.pmf.hr>wrote:

> As first, good luck with this list!
>
> I'm in search for best examples of "code is data" paradigm in Common
> Lisp. For most CL-ers, it probably means "macros", but eval, backquote,
> anything that processes the code as data is of interest. As "best" I
> think on the most surprising, powerful, sophisticated examples, not
> necessarily of a pedagogical value.
>
> Imagine that someone invited you to write the presentation "Five best CL
> macros ... I seen" or "Five best CL macros ... I wrote." What would you
> chose and why?
>
> Kazimir Majorinc
>
>
>
>
>
> _______________________________________________
> pro mailing list
> pro at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/pro
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/pro/attachments/20100905/40c6e9ce/attachment.html>


More information about the pro mailing list