Need Scheme Help

Anubis

No Lifer
Aug 31, 2001
78,712
427
126
tbqhwy.com
need help with this

Write a scheme function called substitute that takes three inputs (two atoms and a list) and returns the list modified so that each occurrence of the first atom is replaced by the second atom. For example: (substitute 'b 'c '(a b c b)) will evaluate to (a c c c). Store your code in the file substitute.s.
 

z0mb13

Lifer
May 19, 2002
18,106
1
76
are you taking cs61a at berkeley??? or maybe cs 3???

edit: here is the answer

(define (subsitute a b ls)
(if ((eq a (car ls)))
(set-car! (car ls) b)
(subsitute a b (cdr ls)))

not 100% sure about the syntax though
 

Anubis

No Lifer
Aug 31, 2001
78,712
427
126
tbqhwy.com
no its not me its for my roomate and we're not at UC berkley. we go to Dickinson College in Carlsile Pa. and hes in Programing Langurage structures. 300 level class