I'm doing some homework in Lisp, using clisp to test, and I'm loading this code and running in in clisp
(defun myreverse (thelist)
(reverse thelist)
(print thelist)
(if (equal thelist nil)
nil
(if (consp (first thelist))
(cons (myreverse (reverse (first thelist)))
(myreverse (reverse (rest thelist))))
(cons (first thelist) (myreverse (rest thelist))))))
I'm kind of new to Lisp, but this code isn't reversing thelist at all, my output is:
[18]> (myreverse '(a (b c) d))
(A (B C) D)
((B C) D)
(C B)
(B)
NIL
(D)
NIL
(A (C B) D)
The first line of my code says (reverse thelist), why isn't it reversing for the first print statement? Am I missing something?
(null thelist)is more idiomatic than(equal thelist nil)in Common Lisp.