clisp を使用して Lisp で宿題をやっていて、このコードを読み込んで 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))))))
私は Lisp の初心者ですが、このコードはまったく反転thelist
していません。私の出力は次のとおりです。
[18]> (myreverse '(a (b c) d))
(A (B C) D)
((B C) D)
(C B)
(B)
NIL
(D)
NIL
(A (C B) D)
私のコードの最初の行は(reverse thelist)
、なぜ最初の print ステートメントを逆にしないのですか? 何か不足していますか?