about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/prime1.scm
blob: 35f7a70f88e8a6f1e830a73b8a7648ed6a610e1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(define (prime? n)
  (null? (filter (lambda (x) (= (remainder n x) 0))
                 (range 2 (- n 1)))))

(define (range from to)
  (if (> from to)
      '()
      (cons from (range (+ from 1) to))))


(define (filter predicate data)
  (cond ((null? data) '())
        ((predicate (car data))
         (cons (car data) (filter predicate (cdr data))))
        (else (filter predicate (cdr data)))))




;; try (filter prime? (range 2 100))