Alex Rivera | Logout

Renaming lambda in Common Lisp

Asked 2012-03-04T18:06:28.360
12

I started learning Common Lisp recently, and (just for fun) decided to rename the lambda macro.

My attempt was this:

> (defmacro λ (args &body body) `(lambda ,args ,@body))

It seems to expand correctly when by itself:

> (macroexpand-1 '(λ (x) (* x x)))
(LAMBDA (X) (* X X))

But when it's nested inside an expression, execution fails:

> ((λ (x) (* x x)) 2)
(Λ (X) (* X X)) is not a function name; try using a symbol instead

I am probably missing something obvious about macro expansion, but couldn't find out what it is.

Maybe you can help me out?

edit: It does work with lambda:

> ((lambda (x) (* x x)) 2)
4

edit 2: One way to make it work (as suggested by Rainer):

> (set-macro-character #\λ (lambda (stream char) (quote lambda)))

(tested in Clozure CL)

Edit
Report

1 Answer

2

You might also think of LAMBDA as an operator which, given a term and a list of free variables, returns a function. This p.o.v. takes LAMBDA out of the family of basic functions and elementary macros -- at least as far as the interpreter is concerned.

answered 2012-10-12T03:05:18.833

Your Answer