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

phone: 1.520.390.3995



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@common-lisp.net
http://common-lisp.net/cgi-bin/mailman/listinfo/pro