HOME

Use literal λ (lambda) character in Common Lisp

Thanks to On Lisp for the details:

(set-macro-character #\λ (lambda (s c) 'lambda))

Allows you to write prettier lambdas in Common Lisp:

(mapcar (λ (x) (* 5 x)) '(1 2 3 4))
(5 10 15 20)

Unlike the (defmacro λ ...) you can really use it everywhere you can use lambda. For example, anonymous recursion:

(funcall
  ((λ (x) (λ (&rest y) (apply x x y)))
    (λ (f x) (if x (+ (first x) (funcall f f (rest x)))
                   0)))
  '(1 2 3 4))
10

Date: 2011-07-31

Copyright © 2011 Hraban Luyat