Content deleted Content added
Range is iterative, xrange is a generator. |
m →Racket |
||
Line 240:
===Racket===
[[Racket (programming language)|Racket]] provides several related facilities for generators. First, its for-loop forms work with ''sequences'', which are a kind of a producer:
<source lang="
(for ([i (in-range 10 20)])
(printf "i = ~s\n" i))
</source>
and these sequences are also first-class values:
<source lang="
(define 10-to-20 (in-range 10 20))
(for ([i 10-to-20])
Line 253:
But more directly, Racket comes with a generator library for a more traditional generator specification. For example,
<source lang="
#lang racket
(require racket/generator)
|