I'm going through Paul Graham's On Lisp, and trying to implement the functions in Emacs Lisp. One of them is flatten :
(flatten '(a (b c) ((d e) f)))
;; Returns:
(a b c d e f)
Yet for some reason, the implementation given by Paul Graham does not work on Emacs Lisp (always returns nil):
(defun flatten (x)
(cl-labels ((rec (x acc))
(cond ((null x) acc)
((atom x) (cons x acc))
(t (rec (car x) (rec (cdr x) acc)))))
(rec x nil)))
(flatten '(1 (3)))
;; Returns:
nil
Does it have something to do with ELisp's dynamic binding? What's wrong with this code?