Re: A "killer" macro



Eli Bendersky <eliben@xxxxxxxxx> writes:

Hello all,

In short: I'm looking for a "killer" macro - a macro (or a couple of
related ones) that show what Lisp can do and other languages (those
without uniform syntax) can not.

A longer version: Many contemporary languages boast their sharing most
of the functional features of Lisp. Perl, Ruby, Javascript - all have
convenient lists (or arrays), functions as first class objects,
garbage collection, dynamic typing, lexical closures. However, one
thing they lack is uniform syntax, and hence the service of a powerful
built-in macro system such as Common Lisp's "defmacro".
When confronted by fellow programmers with the question "so why is
Lisp so special", I'm looking for that short - not too hard to
understand - snippet of code that will show them *why*. I'm convinced
that such a snippet must involve macros. But all the examples I ran
into so far have been either too simple - and could be easily
implemented another way (for example with Ruby's blocks), or too
complicated.

Any suggestions for such an example ?

I have earlier used an implementation of a lexer macro as an example, see
http://groups.google.no/group/comp.lang.lisp/browse_thread/thread/2d7e3fc62d5cfdbc/a1068634fe42c048?lnk=st&q=darwin-lex&rnum=3#a1068634fe42c048

(Page show just usage, not the implementation, I can post that if you want)
In most languages, the equivalent is an external tool that macine-generate code.
There is also cl-yacc, that define a similar

Another, and a really good example if you are less into compilers and it's tools,
is the binary file macros in Peter Seibels Practical common lisp (chapter 24),
and available online. This is a really good example of good macro usage:

http://www.gigamonkeys.com/book/practical-parsing-binary-files.html


--
Gisle Sælensminde, Phd student, Scientific programmer
Computational biology unit, BCCS, University of Bergen, Norway,
Email: gisle@xxxxxxxxxx
The best way to travel is by means of imagination
.



Relevant Pages

  • Re: Program compression
    ... problems to be solved much more concisely than with Lisp. ... In Common Lisp, it's another one line of code: ... My point is that different languages are based on different things ... it would be impossible for the author of a macro (in the Lisp ...
    (comp.programming)
  • Re: A "killer" macro
    ... related ones) that show what Lisp can do and other languages (those ... which actually doesn't really depend all that much on uniform syntax, ... that to the language as a programmer? ... In lisp you can do it. ...
    (comp.lang.lisp)
  • Re: a LISP raytracer
    ... My languages professor right now is a huge fan ... and not so much with LISP. ... Brevity is another major advantage of MLs, e.g. SML and OCaml, over Lisp. ... > and his "def" macro is a great example of this. ...
    (comp.graphics.rendering.raytracing)
  • Re: A "killer" macro
    ... Many contemporary languages boast their sharing most ... of the functional features of Lisp. ... thing they lack is uniform syntax, and hence the service of a powerful ... Quickly, Macro in Lisp is, in fact, a way to create your own domain ...
    (comp.lang.lisp)
  • Re: making a virtual file system
    ... approaches to MP in other languages. ... preprocessors written in lisp, codegenerators written in lisp. ... The main idea to explore is to try to make macroexpansion partially ... When imploding the macro, you could also easily use this ...
    (comp.lang.lisp)