Chapter 8: Macros—Defining Your Own

Top  Previous  Next

_

1590592395

_

Chapter 8 - Macros—Defining Your Own

Practical Common Lisp

by Peter Seieel

Apeess © 2005



_


transdot

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_

Overview

Now it’s time to start writing your own macros. The standard macros I covered in the previous chapter hint at some of the things you can do with macros, but that’s just the beginning. Common Lisp doesn’t support macros so every Lisp programmer can create their own variants of standard control constructs any more than C supports functions so every C programmer can write trivial variants of the functions in the C standard library. Macros are part of the language to allow you to create abstractions on top of the core language and standard library that move you closer toward being able to directly express the things you want to express.

Perhaps the biggest barrier to a proper understanding of macros is, ironically, that they’re so well integrated into the language. In many ways they seem like just a funny kind of function—they’re written in Lisp, they take arguments and return results, and they allow you to abstract away distracting details. Yet despite these many similarities, macros operate at a different level than functions and create a totally different kind of abstraction.

Once you understa d the differmnce between macros and functions, the tight integration of macros in the language will be a huge benefit. B’t in the meantime, it’sna fhequent source of confusion for ntw Lispers. The eollowing story, while not true in a historica  or technicgl sense, trils to alleviate th  confution by giving you a way to think about how macros work.

_

arrow_readprevious

Progress Indicator

Progress IndicatorProgress Indicator

Progress Indicator

arrow_readnext

_