I finally understand the beauty of a Lisp macro

So, I’m still reading Graham’s On Lisp and I finally (way further in than I should have, but it took me a while to exactly get the implications of car and cdr at first too[1]) understand the benefits of the Lisp macro AS OPPOSED to pre-compiler directive: while a pre-compiler directive (which are also more or less available in Common Lisp) is largely tasked with simply adding context to the code it is invoked on, the Lisp macro has access to the objects as native data structures and can alter the output accordingly. This makes it so simple to make sure that structures like this (which could fail in C because of name collisions): MY_MACRO(x++,y++) will work according to expectations[2].

I often find Lisp a very opaque language which, when understood, brings new levels of clarity to your view of the world, and of language in general. Yes, it has an elegant simplicity, but, when coming from a world where some of these things are simply NOT POSSIBLE, it does become a good deal more difficult.

I suppose it is not dissimilar from an English speaker learning the difference between kennen and wissen (in German)[3]. To me, when I was learning, I knew who I knew and I knew that I knew that. In other languages, however, there is a major difference between what it means “to know” the capital of Assyria (Nineveh) and what it means that “I know” my friend Aaron. This is actually clearer and cleaner language, the separation of vocabulary makes it easier to understand, but, as someone who had never come across that idea in his entire life, I had difficulty, at first, grasping the difference.

This is the way things work in Lisp too. I am more than aware of these constructs, but it is harder to wrap one’s head around the ideas’ implications. I’m just not used to working that way.

  1. [1] the trick is remembering that car is a pointer to the “Contents of the Address part of Register number”. Cdr is a pointer to the next point in the data structure (“Contents of the Decrement part of Register number”)
  2. [2] this would be done through gensym, in case anyone cares
  3. [3] basically, sapientia and scientia (for you Romance language speakers)
This entry was posted in Common Lisp, Languages, Lisp, Lisp2. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>