我想製作一個程序,它將重寫給定的行而不在輸出行中有重複項。我使用這個網站,作爲一個編譯器: https://www.tutorialspoint.com/execute_lisp_online.phpCommon Lisp lambda表達式錯誤
這裏是我的代碼
(SETQ X (LIST 2 -3 (LIST 4 3 0 2) (LIST 4 -4) (LIST 2 (LIST 2 0 2))-3))'
(DEFUN SEARCHDEEP (WHAT WHERE) ;Function will find out if atom `WHAT`is in a row `WHERE` => works fine
(COND
((NULL WHERE) NIL)
(T (OR
(COND
((ATOM (CAR WHERE)) (EQUAL WHAT (CAR WHERE)))
(T (SEARCHDEEP WHAT (CAR WHERE)))
)
(SEARCHDEEP WHAT (CDR WHERE))
)
)
)
)
(DEFUN REMDOUBLES (INPUT OUTPUT)
(
(COND
((NULL INPUT) NILL) ;recursion exit
(T ; funstion
(OR ; step into or go forward
(COND
((ATOM (CAR INPUT)) (COND
((NOT (SEARCHDEEP (CAR INPUT) OUTPUT)) (APPEND OUTPUT INPUT)) ;if this atom wasn't added => append
)
)
(T (REMDOUBLES (CAR INPUT) OUTPUT)) ; step into (car input => list
)
(REMDOUBLES (CRD INPUT) OUTPUT) ; go forward, car input is anatom
)
)
)
)
)
(SETQ OUT (QUOTE)) ;Empty row
(REMDOUBLES X OUT)
(PRINT OUT)
我花了2小時以來檢查這些代碼,並在這裏其他的答案,堆棧,但我不知道是什麼我在這裏想念嗎?
我收到此錯誤:
*** - SYSTEM::%EXPAND-FORM:
(COND ((NULL INPUT) NILL)(T(OR (COND ((ATOM (CAR INPUT)) (COND ((NOT (SEARCHDEEP (CAR INPUT) OUTPUT))(APPEND OUTPUT INPUT)))) (T (REMDOUBLES (CAR INPUT) OUTPUT))) (REMDOUBLES (CRD INPUT) OUTPUT)))) should be a lambda expression
很抱歉的格式,我在函數式編程和Lisp新手,我不知道應該如何正確地完成。
'(DEFUN REMDOUBLES(輸入輸出)'和'(COND')之間有一個額外的左括號。正確縮進代碼!任何半像素的編輯都會爲你縮進。 – Gilles
在第('(NULL INPUT)NILL)行中還有一個錯誤,應該是'((NULL INPUT)NIL)' –