我正在学习Common Lisp,我一直在尝试编写一个函数来反转列表。这是功能,但每次我尝试运行它时都会出现“Segmentation Fault(Core Dumped)”
(defun reverseList(x)
(if (cdr x)
(cons (reverseList x) (car x))
(car x)))
(reverseList '(1 2 3))
答案 0 :(得分:0)
我认为这会奏效:
(define reverseList(lambda(x)(
if (null? (cdr x))
(cons (car x) '())
(append (reverseList (cdr x)) (cons (car x) '()))
)
)
)