Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

A. Epilogue > Macro Guild Melee Fighters

Macro Guild Melee Fighters

Lisp Dialect

Common Lisp

Synopsis

True macros are one of Lisp’s most unique and amazing features. In fact, the reason Lispers put up with all those annoying parentheses in their code is that those parentheses enable the awesome Lisp macro system.

image with no caption

True macros allow you to add new functionality to Lisp in a very fundamental way. Experienced Lispers can use macros to make their Lisp compiler/interpreter do their bidding cleanly and elegantly.

How It Kills Bugs

By using macros, an experienced Lisper can minimize code duplication, and better tailor the underlying language to the problem at hand. This leads to cleaner code and fewer bugs.

Example A-2. Example

(defmacro three-way-if (expr a b &rest c)
   (let ((val (gensym)))
       `(let ((,val ,expr))
          (cond ((and (numberp ,val) (zerop ,val)) ,a)
                (,val ,@c)
                (t ,b)))))

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint