2
我試圖做一個簡單的替換方法作爲一個新的Lisp用戶,但不明白爲什麼這不能正常工作。我的替換函數有問題
;replace element e1 with element e2 in a list L
(defun my-replace (e1 e2 L)
(cond
;if the first of L is e1, cons e2 & rest L
((equal (car L) (e1)) (cons (e2) (my-replace (e1 e2 (cdr L)))))
;else cons e1 & rest L
(t (cons (e1) (my-replace (e1 e2 (cdr L)))))))