chickadee » integer-map » fxmapping-accumulate

fxmapping-accumulate proc seed₁ seed₂ procedure

The arguments have the following types:

  • proc : (* … → fxmapping * …) * * … → fixnum * * * …
  • seed₁, seed₂, … : *

Similar to fxmapping-unfold, except that a single procedure controls the unfolding of a new fxmapping. Let n be the number of seeds. proc is applied to a procedure abort-with-result and the seeds, in that order, and is expected to return n + 2 values: a key (fixnum), an associated value, and n new seed values. The key/value association is added to the new fxmapping, and unfolding continues with the new seeds. If, instead, abort-with-result is invoked on any number of arbitrary values, then the current continuation is discarded and the new fxmapping along with the arguments passed to abort-with-result are delivered as multiple values to the continuation that was in effect when fxmapping-accumulate was called.

It is an error for the number of seeds to vary between steps of the unfolding process. If different steps of this process produce associations with the same key, then the first such association takes precedence.

Example:

(let-values (((fxmap s)
              (fxmapping-accumulate
               (lambda (abort-with-result i)
                 (if (< i -3)
                     (abort-with-result 'finished)
                     (values i (square i) (- i 1))))
               -1)))
  (values (fxmapping->alist fxmap) s))
 ⇒ ((-3 . 9) (-2 . 4) (-1 . 1))
   finished