Next: , Previous: Main looping macros, Up: Macros for writing loops


6.3.2 Sequence types

— sequence type: list* elt-var list
— sequence type: vector* elt-var vector
— sequence type: string* elt-var string
— sequence type: count* elt-var start [end [step]]
— sequence type: input* elt-var input-port reader-proc
— sequence type: stream* elt-var proc initial-seed

For lists, vectors, & strings, the elt-var is bound to the successive elements of the list or vector, or the successive characters of the string.

For count*, the elt-var is bound to the elements of the sequence start, start + step, start + 2*step, ..., end, inclusive of start and exclusive of end. The default step is 1, and the sequence does not terminate if no end is given or if there is no N > 0 such that end = start + Nstep. (= is used to test for termination.) For example, (count* i 0 -1) does not terminate because it begins past the end value, and (count* i 0 1 2) does not terminate because it skips over the end value.

For input*, the elements are the results of successive applications of reader-proc to input-port. The sequence ends when the reader-proc returns an end-of-file object, i.e. a value that satisfies eof-object?.

For stream*, the proc receives the current seed as an argument and must return two values, the next value of the sequence & the next seed. If the new seed is #f, then the previous element was the last one. For example, (list* elt list) is the same as

          (stream* elt
                   (lambda (list)
                     (if (null? list)
                         (values 'ignored #f)
                         (values (car list) (cdr list))))
                   list)