about summary refs log blame commit diff stats
path: root/js/games/nluqo.github.io/~bh/61a-pages/Lectures/3.5/prime1.scm
blob: 35f7a70f88e8a6f1e830a73b8a7648ed6a610e1b (plain) (tree)





















                                                         
(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))