Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (define atom? (λ (a) (and (not (pair? a)) (not (null? a)))))
- ;; The Little Schemer
- ;; 2. Do It, Do It Again, and Again, and Again...
- (define (lat? l)
- (cond
- ((null? l) #t)
- (else (cond
- ((atom? (car l))
- (lat? (cdr l)))
- (else #f)))))
- (define (member? a lat)
- (cond
- ((null? lat) #f)
- (else (cond
- ((eq? a (car lat)) #t)
- (else
- (member? a (cdr lat)))))))
- ;; --- Tests -----------------------------------------------
- (define (test-lat)
- (and
- (not (lat? '(1 2 3 ())))
- (lat? '(1 2 3))
- ))
- (define (test-member)
- (and
- (member? 1 '(1 2 3))
- (member? 3 '(1 2 3))
- (not (member? 0 '(1 2 3)))
- ))
- (define (test-all)
- (and
- (test-lat)
- (test-member)
- ))
- (println (if (test-all) "OK" "Error"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement