|  |  | Enumerators

## Enumerators

Enumerations are the foundation of collections and are designed to provide the convenience of Lisp's list interface (e.g., `null`, `car`, `cdr`) for all collections. In defining a new collection class, a user must implement at minimum an enumerator class and the enumeration protocol: `enum`, `fin?`, `nxt`, and `now`. For efficiency, users might choose to override more methods such as `len`, `elt`, `elt-setter`, etc. Enumeration behavior is undefined if an enumerator is modified during enumeration.

`<enum>` | `(<any>)` | `C`
`enum` | `(x|<any> => <enum>)` | `G`
| returns initial enum for iterating over `x`. |
`fin?` | `(x|<enum> => <log>)` | `G`
| returns true iff no more elements exist from given enum `x`. |
`nxt` | `(x|<enum> => <enum>)` | `G`
| returns enum pointing to next element in enum `x`. |
`now` | `(x|<enum> => <any>)` | `G`
| returns current element given enum `x`. |
`now-setter` | `(v x|<enum>)` | `G`
| sets current element given enum `x` to `v`. |
`now-key` | `(x|<enum> => <any>)` | `G`
| returns current key given enum `x`. |
`enum` | `(x|<enum> => <enum>)` | `M`
| returns x allowing enumerators to be enumerated. |
`FOR` | `(FOR (,for-clause ...) ,@body)` | `S`
| parallel iteration over collections using enumerations. |

where

`,for-clause` | `== (,var ,col) | ((tup ,keyvar ,var) ,col)` | `L`
| specifies one parallel iteration over a collection `,col` binding successive values to `,var` and optionally keys to `,keyvar`. |

|  |  | Enumerators