特定のパターンを見つけて置き換えるスキームプログラムを作成する必要があり、ネストの1つのレイヤーのみで動作するようにしましたが、リストの次の車がリスト自体である場合、プログラムは適切に再帰しません.
これが私がこれまでに持っているものです:
(define replace
(lambda (source target replacement)
(if (eqv? source target)
replacement
(if (null? source)
'() ;;base case
(if (equal? target (car source))
(cons replacement (replace (cdr source) target replacement))
(cons (car source)
(replace (cdr source) target replacement))
)
)
)
)
)