(define (rem-dig n ds)
(cond
((list? ds)
(remove-digit n (map (lambda(d)(rem-dig n d)) ds)))
(else ds)))
需要将等式谓词从 number-specific 替换为=
general equal?
:
(define (remove-digit digit list)
(cond ((null? list) list)
((equal? digit (car list)) (remove-digit digit (cdr list)))
(else (cons (car list) (remove-digit digit (cdr list))))))
测试:
(rem-dig 1 '(1 2 3 (4556 1)))
;Value 13: (2 3 (4556))
如果允许不正确的点列表,则应对其进行调整,
(define (rem-dig n ds)
(cond
((list? ds)
(remove-digit n (map (lambda(d)(rem-dig n d)) ds)))
((pair? ds)
(let* ((x (last-pair ds))
(y (cdr x))
(z (set-cdr! x ()))
(ds (rem-dig n ds))
(x (last-pair ds)))
(if (not (equal? n y))
(set-cdr! x y))
ds))
(else ds)))