I want to flatten a list in Lisp, for example:
(1 2 (3 (4 5) 6)) --> (1 2 3 4 5 6)
Here is the code I wrote:
(defun flatten (l)
(cond
((endp l) nil)
((listp (car l)) (cons (flatten (car l)) (flatten (cdr l))))
((atom (car l)) (cons (car l) (flatten (cdr l))))))
I don't know what is wrong here. I even found on a forum the exact same code and the guy said that it is working but this code is not changing my list at all. Some help?