|
3509 | 3509 | For comprehensions consist of a vector of bindings, with optional modifiers, and a
|
3510 | 3510 | user specified body in an implicit ``do`` block.
|
3511 | 3511 |
|
3512 |
| - Symbol bindings look like standard ``let`` bindings without destructuring. Values |
3513 |
| - bound to symbols should be sequences or otherwise seqable. The body of the ``for`` |
3514 |
| - comprehension will be executed with the given symbol bound to successive values of the |
3515 |
| - sequence. If multiple sequences are bound to symbols, iteration will proceed in a |
3516 |
| - nested fashion with latest sequences iterated first and earlier sequences iterated |
3517 |
| - later (as nested ``for`` loops in procedural languages). |
| 3512 | + Symbol bindings look like standard ``let`` bindings. Values bound to symbols should be |
| 3513 | + sequences or otherwise seqable. The body of the ``for`` comprehension will be executed |
| 3514 | + with the given symbol bound to successive values of the sequence. If multiple sequences |
| 3515 | + are bound to symbols, iteration will proceed in a nested fashion with latest sequences |
| 3516 | + iterated first and earlier sequences iterated later (as nested ``for`` loops in |
| 3517 | + procedural languages). |
3518 | 3518 |
|
3519 | 3519 | For example, a simple non-nested for comprehension will yield::
|
3520 | 3520 |
|
|
3554 | 3554 |
|
3555 | 3555 | (not (even? (count bindings)))
|
3556 | 3556 | (throw (ex-info "for expression must have an even number of bindings"
|
3557 |
| - {:bindings bindings})) |
3558 |
| - |
3559 |
| - (not (symbol? (first bindings))) |
3560 |
| - (throw (ex-info "for expression bindings must start with symbol binding" |
3561 | 3557 | {:bindings bindings})))
|
3562 | 3558 |
|
3563 | 3559 | (let [;; Generate the body of a for binding iterator, applying any relevant
|
|
3626 | 3622 | ;; (which will be applied to this iterator) and additional
|
3627 | 3623 | ;; bindings (which will be generated as new, inner iterators).
|
3628 | 3624 | groups (split-with (fn [pair]
|
3629 |
| - (not (symbol? (first pair)))) |
| 3625 | + (keyword? (first pair))) |
3630 | 3626 | (rest pairs))
|
3631 | 3627 | mods (first groups)
|
3632 | 3628 | rest-bindings (second groups)
|
|
0 commit comments