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

David McClain dbm at refined-audiometrics.com
Tue Sep 7 05:27:47 UTC 2010


All the elaborate macros aside, here is a very common idiom that  
takes direct advantage of the "code-is-data" aspects of Lisp:

(fli:copy-pointer p :type `(:c-array ,eltyp ,nel))

That back-quoted parameter construction shows a dynamic construction  
of a function call, taking runtime data and making it part of code.  
The exact function being called is unimportant here. I just copied it  
from some code that I had laying about, extracted from this function:

(defmethod row-major-array-pointer ((p fli::pointer))
   (let ((dims (fli:foreign-array-dimensions p)))
     (if (rank-1-p dims)
         p
       (let* ((nel   (reduce #'* dims))
              (eltyp (fli:foreign-array-element-type p)))
         (fli:copy-pointer p :type `(:c-array ,eltyp ,nel)))) ;; <--  
here is the dynamic construction...
     ))


Dr. David McClain
Chief Technical Officer
Refined Audiometrics Laboratory
4391 N. Camino Ferreo
Tucson, AZ  85750

email: dbm at refined-audiometrics.com
phone: 1.520.390.3995
web: http://refined-audiometrics.com



On Sep 5, 2010, at 05:24, Kazimir Majorinc 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/20100906/7a76d6a3/attachment.html>


More information about the pro mailing list