我有以下代码:
(define (atom? x)
(and (not (null? x))
(not (pair? x))))
(define delete
(lambda (atom l)
(cond
((null? l) '())
((atom? l)
(cond
((not(eq? atom l)) l)
(else '())
)
)
(else (cons (delete atom (car l)) (delete atom (cdr l))) )
)
)
)
目标是从该列表中删除某个字符。例如,
(delete 'a '(a b a) ) ==> (b)
相反,我得到的是:
(delete 'a '(a b a) )==> (() b ())
我对这个计划一无所知。如果找到值,我尝试过不返回任何内容,但这只会使其表现为:
(delete 'a '(a b a) )==> (#<void> b #<void>)
有什么想法吗?非常感谢!
(define delete
(lambda (atom l)
(cond
((null? l) '())
((atom? (car l))
(cond
((eq? atom (car l)) (delete atom (cdr l)))
(else (cons (car l) (delete atom (cdr l))))
)
)
(else (cons (delete atom (car l)) (delete atom (cdr l))))
)
)
)
这个解决方案更基本,更容易从基本原理中理解。