Common Lisp the Language, 2nd Edition


next up previous contents index
Next: Gatherers Up: Generators and Gatherers Previous: Introduction

B.2. Generators

change_begin
These functions create and process generators.


[Function]
generator series

Given a series, generator returns a generator containing the same elements.


[Macro]
next-in generator {action}*

next-in returns the next element in the generator generator. The actions can be any Lisp expressions. They are evaluated if and only if no more elements can be retrieved from generator. If there are no more elements and no actions, it is an error. It is also an error to apply next-in to a generator a second time after the generator has run out of elements. As an example of generators, consider the following.

(let ((x (generator (scan '(1 2 3 4))))) 
  (with-output-to-string (s) 
    (loop (prin1 (next-in x (return)) s) 
          (prin1 (next-in x (return)) s) 
          (princ "," s)))) 
 => "12,34,"


change_end


AI.Repository@cs.cmu.edu