Primes by Trial Division - Scheme R³

29 August 2017

Gambit Scheme only:

(define (last-pair liszt)
  (let lp ((liszt liszt))
    (let ((tail (cdr liszt)))
      (if (pair? tail) (lp tail) liszt))))

All systems:

(define (div? n liszt)
  (call-with-current-continuation
     (lambda (exit)
        (map (lambda (p) (if (zero? (remainder n p)) (exit #t))) liszt)
        #f)))

(define (primes n)
  (letrec ((primes (list 2)))
     (do ((count 3 (+ 1 count))) ((= (length primes) n) primes)
        (if (div? count primes)
          #t
          (set-cdr! (last-pair primes) (list count))))))

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026

Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Primes Benchmark Source

Online Manuals

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

Primes Benchmark Results

Other LISPs

Cambridge LISP

Common LISP

Domain Lisp

Golden Common LISP

INTERLISP

Interlisp/65

LISP/80

Pearl LISP

Scheme R³

XLISP