[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.3 Iterators

The iterators are objects which treat like lists.

If you want to process lists, you will write a code which shows as follows.

(define (foo lst)
  (cond ((null? lst) #f)
        ((pred? (car lst)) <processes>)
        (else (foo (cdr lst)))))

You can rewrite the example using the iterators.

(define (foo lst)
  (cond ((iterator-null? lst) #f)
        ((pred? (iterator-car lst)) <processes>)
        (else (foo (iterator-cdr lst)))))

Lists can treat as iterators.

The iteratable object is an object which can extract an iterator by procedure->iterator procedure.

Lists, strings and vectors are iteratable objects.

Function: iterator? obj

returns true if the object is an iterator.

Function: iterable? obj

returns true if the object is an iteratable object.

Function: iterator-null? iterator

returns true if the iterator is terminated.

Function: iterator-car iterator

returns an object which indicates the iterator.

Function: iterator-cdr iterator

gets a next iterator.

Function: ->iterator iterable

gets an iterator from the iterable object.

Function: iterator->list iterator

converts the iterators to a list.

Function: compound-iterator iterator …

concatenates the iterators.
If iterator itr1, itr2 and itr3 are {1, 2, 3, {4, 5 and {6, 7 respectively, the result will be {1, 2, 3, 4, 5, 6, 7.

Function: filtered-iterator proc iterator

returns the iterator in which objects satisfies the proposition.
If the given iterator is {1, 2, 3, 4, the result of (filtered-iterator even? itr) will be {2, 4.

Function: group-iterator iterator …

returns the iterator whose elements are lists which are concatenated each result of given iterator.
If iterator itr1, itr2 and itr3 are {1, 2, 3, {4, 5 and {6, 7, respectively, the result of (group-iterator itr1 itr2 itr3) will be {(1 4 6), (2 5 7).

Function: list-group-iterator list …

returns the iterator whose elements are lists which are concatenated each car of given list.
An error is occured if all length of the lists are not equal, one of the lists is circulated or not a proper list.

Function: make-csv-iterator file [separator] [quote] [newline] [comment]

returns the iterator which analyses the given CSV file.
Default value of separator is ’,’, quote is ’"’, newline is ’\n’ and comment is #f.

Function: make-real-number-iterator start end step

returns the iterator which increse(decrese) from start to end by step.

Function: make-string-tokenizer string charset

returns the iterator whose elements are strings tokenized by the given charset.
charset must be a character set or a string.

Function: make-tree-walker tree

returns the iterator which traverses the given tree.
If the given tree is ((1 2) 3 ((4 5) 6)), the result will be {1, 2, 3, 4, 5, 6.


[ << ] [ < ] [ Up ] [ > ] [ >> ]

This document was generated on August 9, 2012 using texi2html 5.0.