Tuesday, June 08, 2004

Scheme woes - too tired now. Will be obvious in the morning.

insertR is a function that adds its first parameter into a list (its third parameter) directly after the first occurence of its second parameter.
I have MZScheme. I execute:
    (insertR 3 2 '(1 2))

I get
    (1 2 3)

That floats my boat. Now I fire up SISC 1.8.8. Again, I execute:
    (insertR 3 2 '(1 2))

This time I get:
    (1 2)

What gives?

(define insertR
(lambda (new old lat)
(cond
((null? lat) '())
(else
(cond
((eq? (car lat) old) (cons old (cons new (cdr lat))))
(else
(cons (car lat) (insertR new old (cdr lat)))))))))

No comments: