【发布时间】:2012-02-07 12:38:17
【问题描述】:
我在 Lisp 中做一些功课,使用 clisp 进行测试,我正在加载这段代码并在 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),为什么第一条打印语句不反转?我错过了什么吗?
【问题讨论】:
-
(null thelist)在 Common Lisp 中比(equal thelist nil)更惯用。
标签: common-lisp reverse clisp