-2
我是新来口齿不清,我遇到了我的家庭作业,要求消除所有的后续数字只有第一个号码将在列表中的问题 例如(1 1 2 1 3 1 1 1)
将(1 2 1 3 1)
消除所有后续号码口齿不清
我的代码是:
;the input is (1 1 2 1 3 1 1 1)
(defun eli(x)
; this condition will check if x is empty or has only one element
(if (or(null x)(null (cdr x))) x
; if the first element is 1 but the second element is not 1
(if (and (= 1 (car x))(not (= 1 (car (cdr x)))))
; if true then append 1 and call the function with the rest of the list
(cons (car x)(eli(cdr x)))
; if false call the function recursivaly
(eli(cdr x))
)))
; the output is (1 2 1 3 1 1)
这个代码生成(1 2 1 3 1 1)
任何想法,我做错了什么?
目前还不清楚输入哪个输出。目前还不清楚你的代码应该做什么。你可能想要评论你的代码。 –
我说我的代码更清晰,请注意,实际输出必须是'(1 2 1 3 1)'。我无法得到它 –
请告诉我们Lisp在哪里为某些输入生成输出。发布实际的Lisp交互。将交互添加到您的问题。 –