-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交互。將交互添加到您的問題。 –