

Let Over Lambda—50 Years of Lisp - ananthrk
http://letoverlambda.com/index.cl/toc

======
asdr
very very good book about lisp macros. with pg's onlisp, you don't need any
other source.

~~~
Estragon

      with pg's onlisp, you don't need any other source.
    

Relevant excerpt from the introduction

    
    
      There are very few good references or tutorials on macro
      construction. Paul Graham's On Lisp[ON-LISP] is one of the
      exceptions. Every word of On Lisp is required reading for anyone
      interested in macros. On Lisp and Graham's other writings were the
      most important inspirations for the creation of the book you are
      reading now. Thanks to Paul Graham and other lisp writers, the power
      that macros provide programmers is widely discussed, yet is
      unfortunately still widely misunderstood. Despite the wisdom regarding
      macro programming that can be gleaned from a simple perusal of On
      Lisp, few programmers make the connection between the macro and their
      real-life programming problems. While On Lisp will show you the
      different types of macros, this book will show you how to use them.
    

Having read about half of _On Lisp_ , I think that's a fair claim. I am very
glad to be reading it, it is a wonderful book, and thanks to it I know what a
macro is and what it can do, but haven't really come away with a good feel for
when to use them myself in my own code. (It may be that the logic of my code
is too simple to require them.) Whether _Lambda Over Let_ lives up to its
claim of showing how to use them, I don't know. Definitely going to take a
look.

------
danking00
In the "Macro Basics" section, he seems to completely glaze over the _other_
problem with unhygenic macros.[1]

Consider:

    
    
      (defmacro square (x)
        `(* ,x ,x))
    
      (let ((* my-vector-dot-product))
        ...
        (square (* bar baz)))
    

He seems a bit brash in his attacks on Scheme and insistence that hygenic
macros are bad. He doesn't even mention Clinger's explicit renaming macros
which solve the problem without using a DSL (an approach which he derides).

Also, what about side effecting arguments to macros? I'm hesitant to put too
much credence in this book when it seems to ignore significant problems with
defmacro.

[1] <http://letoverlambda.com/index.cl/guest/chap3.html#sec_5>

~~~
astine
There are two problems with your example. First is that Common Lisp is a
lisp-2 so the '*' function won't actually be rebound at all.

Secondarily, and more importantly, every unhygienic lisp I've used has had a
broader namespacing system which takes care of this. The compiler warns you
whenever you are about to rebind something within the same namespace.

~~~
oconnore
Like, Common Lisp? (Clozure)

    
    
        ? (defun plus (&rest x) (apply #'+ x))
        PLUS
        ? (defmacro mplus (&rest x) `(plus ,@x))
        MPLUS
        ? (flet ((plus (&rest x) (apply #'* x))) (mplus 4 9))
        36 ;; Uh oh, looks like my function was rebound
        ? (plus 4 9)
        13
    

How about functions in the CL package?

    
    
        ? (defmacro mplus (x y) `(+ ,x ,y))
        MPLUS
        ? (flet ((+ (x y) (- x y))) (mplus 8 4))
        4

~~~
astine
Your second example throws an error for me. (SBCL)

The first doesn't (it appears flet doesn't trigger the error in this
situation) but the package system still mitigates the damage in practice. I've
written a lot of macros and haven't yet accidentally rebound a special
function with flet which a macro relied upon.

~~~
sedachv
> Your second example throws an error for me. (SBCL)

According to the CL standard, you shouldn't be able to redefine or shadow
special operators, functions, or macros in the COMMON-LISP package. SBCL does
the right thing by the spec, but it's really a weakness of the spec that makes
CL less general than it can be.

This restriction and the multiple namespaces of Common Lisp (and given
appropriate use of gensym) is why almost all of the time CL macros work
without need of hygiene. But there's nothing stopping surprises when you call
functions or macros defined in packages other than COMMON-LISP.

------
sedachv
I wrote a review a couple of years ago:
[http://carcaddar.blogspot.com/2009/04/review-let-over-
lambda...](http://carcaddar.blogspot.com/2009/04/review-let-over-lambda.html)

Chapters 7 and 8 haven't been posted online; it's worth purchasing the book to
read them.

------
yoshiks
Oops,they shouldn't translate the title into Japanese at News (see about the
book), as its sold as "Let over Lambda 1.0" as same as English. Of course
contents are translated.

