【发布时间】:2021-05-24 09:14:17
【问题描述】:
我有以下代码:
(defun list-append (L1 L2)
"Appending L1 by L2."
(if (null L1)
L2
(cons (car L1) (list-append (cdr L1) L2))))
(defun list-reverse (L)
"Create a new list containing the elements of L in reversed order."
(if (null L)
nil
(list-append (list-reverse (cdr L))
(list (car L)))))
当我运行以下命令时:
(list-reverse '(a (b c) ((l k (t)) h i)))
我得到的输出是这样的:
(((L K (T)) H I) (B C) A)
但是,我试图让它反向打印出列表及其子列表,如下所示:
((I H ((T) K L)) (C B) A)
关于如何修改代码来做到这一点的任何建议?
【问题讨论】:
标签: lisp common-lisp clisp