<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
It's very, very hard to know what "best macro" means.  It's<br>
like asking for the "best function".  Perhaps what people<br>
mean is the "cutest" or "most remarkable" macro.<br>
<br>
I'm rather proud of the macros I wrote for the logging<br>
system in QRes.  I really ought to refactor it out and<br>
open-source it.  What I wanted to do was to encourage<br>
people to add logging forms to their code.  One reason<br>
people resist putting them in is that they worry about<br>
the time (compute) overhead when logging is turned<br>
off.  So I thought to myself, what's the lowest we<br>
could get it to be?  Well, suppose that every logging<br>
statement turns into a read of a special variable<br>
and a check to see whether it's NIL or not?  You<br>
can't do a whole lot better than that, I'd think.<br>
Now, let's say you have hierarchical names of<br>
categories.  You turn on logging for "foo.bar",<br>
and you do not want calls that log to "foo.quux"<br>
to get turned on; they too should be very, very<br>
fast.  But you do not know in advance the names of<br>
all the logging categories there might be.  I guess<br>
I could have required the programmer to add the<br>
categories to a file, but ANYTHING that makes<br>
logging harder will discourage people from<br>
adding logging statements.  If you try to do this,<br>
you'll find that it's a bit tricky.  You need some<br>
eval-when stuff.  You need to create symbols dynamically.<br>
It's not rocket science, but it's sort of cool and it<br>
might be useful to others.<br>
<br>
-- Dan<br>
<br>
Yakov Zaytsev wrote:
<blockquote
 cite="mid:AANLkTikifj3VL_52S4vHZmP1EFG3Qs=rubuzcc42FGsx@mail.gmail.com"
 type="cite">My best macro so far ;-)
  <div><br>
  </div>
  <div>
  <div>(defmacro access-slot (object &rest slot-names)</div>
  <div>  `(ff:fslot-value-typed (ff:foreign-pointer-type ,object)</div>
  <div>                         :c (ff:foreign-pointer-address ,object)</div>
  <div>                         ,@slot-names))</div>
  <div><br>
  </div>
  <div>(defmacro define-struct-getter (struct package &rest slots)</div>
  <div>  (loop for s in slots</div>
  <div>     do (let ((acc (intern (concatenate 'string (symbol-name
struct) "-" (symbol-name s))))</div>
  <div>                   (sp (intern s package)))</div>
  <div>               (eval `(defmacro ,acc (object)</div>
  <div>                        `(access-slot ,object ',',sp))))))</div>
  <div><br>
  </div>
  <div>because it is a macro which writes macros which uses macro. My
first real world macro.</div>
  <br>
  <div class="gmail_quote">On Sun, Sep 5, 2010 at 4:24 PM, Kazimir
Majorinc <span dir="ltr"><<a moz-do-not-send="true"
 href="mailto:kazimir@chem.pmf.hr">kazimir@chem.pmf.hr</a>></span>
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">As
first, good luck with this list!<br>
    <br>
I'm in search for best examples of "code is data" paradigm in Common<br>
Lisp. For most CL-ers, it probably means "macros", but eval, backquote,<br>
anything that processes the code as data is of interest. As "best" I<br>
think on the most surprising, powerful, sophisticated examples, not<br>
necessarily of a pedagogical value.<br>
    <br>
Imagine that someone invited you to write the presentation "Five best CL<br>
macros ... I seen" or "Five best CL macros ... I wrote." What would you<br>
chose and why?<br>
    <br>
Kazimir Majorinc<br>
    <br>
    <br>
    <br>
    <br>
    <br>
_______________________________________________<br>
pro mailing list<br>
    <a moz-do-not-send="true" href="mailto:pro@common-lisp.net">pro@common-lisp.net</a><br>
    <a moz-do-not-send="true"
 href="http://common-lisp.net/cgi-bin/mailman/listinfo/pro"
 target="_blank">http://common-lisp.net/cgi-bin/mailman/listinfo/pro</a><br>
  </blockquote>
  </div>
  <br>
  </div>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
pro mailing list
<a class="moz-txt-link-abbreviated" href="mailto:pro@common-lisp.net">pro@common-lisp.net</a>
<a class="moz-txt-link-freetext" href="http://common-lisp.net/cgi-bin/mailman/listinfo/pro">http://common-lisp.net/cgi-bin/mailman/listinfo/pro</a>
  </pre>
</blockquote>
</body>
</html>