Generator (computer programming): Difference between revisions

Content deleted Content added
Range is iterative, xrange is a generator.
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="schemeracket">
(for ([i (in-range 10 20)])
(printf "i = ~s\n" i))
</source>
and these sequences are also first-class values:
<source lang="schemeracket">
(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="schemeracket">
#lang racket
(require racket/generator)