Next: , Previous: , Up: loops generators   [Index]


1.16.4.2 Loop generators

Generator Syntax: :do (?lb ...) ?ne1? (?ls ...)
Generator Syntax: :do (let (?ob ...) ?oc ...) (?lb ...) ?ne1? (let (?ib ...) ?ic ...) ?ne2? (?ls ...)

Defines a generator in terms of a named let, optionally decorated with inner and outer let. This generator is for defining other generators. (In fact, the reference implementation transforms any other generator into an instance of fully decorated :do.)

The generator is a compromise between expressive power (more flexible loops) and fixed structure (necessary for merging and modifying generators).

In the fully decorated form, the following syntactic variables are present:

?ob

Outer binding.

?oc

Outer command.

?lb

Loop binding.

?ne1?

Not end predicate.

?ib

Inner binding.

?ic

Inner command.

?ne2?

Not end predicate.

?ls

Loop step.

They define the following loop skeleton:

(let (?ob ...)
  ?oc ...
  (let loop (?lb ...)
    (when ?ne1?
      (let (?ib ...)
        ?ic ...
        payload
        (when ?ne2?
          (loop ?ls ...))))))

where ?oc and ?ic are syntactically equivalent to forms in the body of a begin, i.e. they do not begin with a ?definition. The latter requirement allows the code generator to produce more efficient code for special cases by removing empty let expressions altogether.