Reputation: 171
Im trying to create a function such that if you query this :
(color 'dress liste)
it should return 'blue
. assuming that listE is defined for us (define liste '((hat . red) (dress . blue) (coat . yellow)))
I think i'm close: here is what i have done:
(define (color x List1)
(cond (((null? List1) '()))
((equal? x (caar List1) (cdar List1)))
(else (color x (cdr List1)) ))
)
Upvotes: 0
Views: 71
Reputation: 74645
Your implementing the assoc
function. Your code only needed some correction of its parenthesis. Compare with:
(define (color x List1)
(cond ((null? List1) '())
((equal? x (caar List1)) (cdar List1))
(else (color x (cdr List1)))))
Upvotes: 1