Two-Way Recursive Functions
> (define (censor2 lst)
; Returns LST with no instances of BAD.
(cond ((null? lst) ())
((not (list? Lst)) lst)
((eq? (car lst) 'BAD)
(censor2 (cdr lst)) )
(#t (cons (censor2 (car lst))
(censor2 (cdr lst)) ) ) ) )
CENSOR2
> (censor2 '(This bad list (has a bad sublist)))
(THIS LIST (HAS A SUBLIST))
Previous slide
Next slide
Back to first slide
View graphic version