Reputation: 121
Clojure's let is more concise than Common Lisp with less parentheses:
;Clojure
(let [a 1 b 2]
(+ a b))
;Common Lisp
(let ( (a 1) (b 2))
(+ a b))
How would you write a macro in Common Lisp to be equivalent?:
(letmac ( a 1 b 2)
(+ a b))
Upvotes: 3
Views: 202
Reputation: 60064
(defmacro clojure-let (bindings &body body)
`(let ,(loop for (a b) on bindings by #'cddr collect (list a b))
,@body))
see how it works:
> (macroexpand-1 '(clojure-let (a b c d) (foo) (bar)))
(LET ((A B) (C D)) (FOO) (BAR)) ;
T
Your code might be more readable for a clojure user, but it will be less readable for a lisper.
A clojurer might get a false sense of security while a lisper will get confused.
Porting Common Lisp code to Clojure is far harder than writing a few simple macros.
Upvotes: 10