【发布时间】:2021-11-12 14:23:09
【问题描述】:
我在编写一个接收列表并返回通过切换列表中的连续元素创建的列表的 Scheme 过程时遇到问题。
例如,如果我打电话给:(newlist ‘((a b) (c d) e f g)),我会得到:‘( (b a) (d c) f e g)
到目前为止,我已经尝试了以下方法,但在尝试编译时出现错误:
(define (newlist givenList)
(cond ; Condition statement
((null? givenList)
'())
((null? (cdr givenList))
(list (car givenList)))
(list (cadr givenList) (car givenList)))
(newlist (cddr givenList)))
cddr:违反合同 预期:(cons/c any/c pair?) 给定:(g)
这种语言与我以前使用过的语言非常不同,所以我承认有点难过。
【问题讨论】: