Apex Predator
Apex Predator

Reputation: 171

Find color Scheme


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

Answers (1)

Dan D.
Dan D.

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

Related Questions