Comment by sinsudo
3 hours ago
I know that the purpose of the page is to compare syntax of common lisp, racket, clojure, and emacs lisp. But some examples could be more idiomatic, for instance instead of
(defun add (a &rest b)
(if (null b)
a
(+ a (eval (cons '+ b)))))
One should avoid eval and use endp instead of null:
(defun add (a &rest b)
(if (endp b) a
(apply #'add (+ a (first b)) (rest b))))
Worse: Using recursion in Common Lisp isn't idiomatic, given that CL doesn't guarantee tail-call optimisation in the specification.
Shouldn't it be (+ a (apply + b))
Almost. It should be (+ a (apply #'+ b)). Common Lisp is a Lisp-2, so a + in the argument position is assumed to be a variable named +, not the function named +, unless you specify otherwise.