I'm currently reading the 4th edition of "The Little Schemer". One early exercise is to create a function insertR
which inserts an value to the right of a given value in a list. The book eventually arrives at the following definition:
(define insertR
(lambda (new old lat)
(cond
((null? lat) (quote ()))
(else (cond
((eq? (car lat) old)
(cons old
(cons new (cdr lat))))
(else (cons (car lat)
(insertR new old
(cdr lat)))))))))
My own definition looked like this:
(define insertR
(lambda (new old lat)
(cond
((null? lat) (quote ()))
((eq? (car lat) old) (cons old (cons new (cdr lat))))
(else (cons (car lat) (insertR new old (cdr lat)))))))
Are they equivalent?