Skip to content

Instantly share code, notes, and snippets.

@shugo
Created March 14, 2012 08:38
Show Gist options
  • Save shugo/2035129 to your computer and use it in GitHub Desktop.
Save shugo/2035129 to your computer and use it in GitHub Desktop.
Schemeではtakeもlazyだった
(use util.stream)
(use srfi-42)
(define (primes)
(stream-filter (lambda (k)
(not (any?-ec (: j 3 (sqrt k) 2) (zero? (modulo k j)))))
(stream-cons 2 (stream-iota -1 3 2))))
(print (stream-take (primes) 20))
(print (stream->list (stream-take (primes) 20)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment