On Lisp gems
Wednesday, September 3, 2003
One of the things that I like about Paul Graham's book On Lisp is that it contains so many gems. For example, on Page 21, Paul says:
"When we define functions with lambda-expressions, we face a restriction which doesn't arise with defun: a function defined in a lambda-expression doesn't have a name and therefore has no way of referring to itself. This means that in Common Lisp we can't use lambda to define a recursive function."But then, in the notes on Pages 387-388, he clarifies that by saying that "we cannot define a recursive function with a single lambda-expression" and goes on to show how the typical factorial example:
(defun fact (n) (if (= n 0) 1 (* n (fact (- n 1)))))could be expressed in terms of anonymous lambda-expressions:(fact 8)
(funcall ((lambda (f) #'(lambda (n) (funcall f f n))) #'(lambda (f n) (if (= n 0) 1 (* n (funcall f f (- n 1)))))) 8)Neat book, eh! And the whole book is like that - a real learning tool. That's why it's listed as one of the 2 "essential" books in my Lisp library.

