PDA

View Full Version : scheme help plz!!!


ryu12341
04-06-2005, 01:34 AM
hey guys!!! im having trouble with scheme. the teacher gave us some sample code.

(define member?
(lambda (e S)
(cond ((null? S) #f)
((eq? e(car S)) #t)
(else return member? e(cdr S)))))

i just want to make sure im understanding this correctly. the function member takes in two lists e and S. if the list in S is empty it returns #f. if the first element in e is equal to the first element in S then it returns #t. then it returns the rest of the list in S. is this correct? for some reason i find scheme to be so tricky.

i also have another question. how do i call this function? i've tried
(member (1) (1 2 4 5))
(member '(1) (1 2 3 4))

i wanted to see if i could get this to output the #t and output the rest of the list in S but I only get a #f and a error message. thanks for the help guys!!!

JRS200x
04-13-2005, 05:54 PM
e is not necessarily a list in this function, it can be an interger value. Its testing if e is the equal to the first element of your list S.

For example call the function using (member 1 '(1 2 3 4)) and it will return true and print (1 2 3 4).

Call if using (member '(1) '(1 2 3 4)) and it will return false, and so on.

You could also do (member '(1) '((1) 2 3 4)) and this would return true.