logoalt Hacker News

sinsudoyesterday at 8:43 PM2 repliesview on HN

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))))

Replies

ludstonyesterday at 11:06 PM

Worse: Using recursion in Common Lisp isn't idiomatic, given that CL doesn't guarantee tail-call optimisation in the specification.

show 2 replies
CodeArtisanyesterday at 10:31 PM

Shouldn't it be (+ a (apply + b))

show 1 reply