2010/02/09

member?

The Little Schemer のmember?
(define member?
  (lambda (a lat)
    (cond ((null? lat) #f)
          ((eq? a (car lat)) #t)
          (else (member? a (cdr lat))))))
The Little Schemer のmember? その2
(define member?
  (lambda (a lat)
    (cond ((null? lat) #f)
          (else (or (eq? a (car lat))
                    (member? a (cdr lat)))))))
もっとすっきり書くには?
(define member?
  (lambda (a lat)
    (eq? a (find (lambda (e)
                   (eq? a e)) lat))))
こんな感じか?
(define member?
  (lambda (a lat)
    (any (lambda (e)
           (eq? a e)) lat)))
Scheme手習い

0 件のコメント:

コメントを投稿