diff --git a/documentation/doc.html b/documentation/doc.html index ee926ea..65838c4 100644 --- a/documentation/doc.html +++ b/documentation/doc.html @@ -92,7 +92,7 @@ (loop ((:for a (in-list '(1 2 3 4))) ;; this works because :acc bindings are promoted "outwards". (:break final) - (:acc final (in-value (initial #f) #t (if (= 3 a)))) + (:acc final (in-value (:initial #f) #t (:if (= 3 a)))) (:acc acc (listing (cons a b)))))
This means that any clause above the final binding will be executed an extra time before the loop exits:
@@ -166,26 +166,26 @@
(:for binding (stop-after iterator pred))
Binds binding
to the values produced by iterator
until pred
applied to that value returns true. It then produces that last value. The iterator is then considered exhausted. Useful in subloops where one might want to end internal iteration without :break-ing.
Accumulating clauses differ from :for-clauses in 2 significant ways. They have a final value available in the final-expr
, and they keep their state throughout the loop. In the case of a loop with one subloop, the :for-clauses reset their state every time the subloop is entered. :acc-clauses will always keep their state.
Another small thing is that for some :acc-clauses, the binding
may sometimes only be visible to the user in the final-expr
, but like :for-clauses they sometimes offer the programmer to name the loop variables.
Many accumulating clauses support an if
form. If such a clause is given, accumulation will only happen if the guard clause returns true.
(:acc binding (listing [(:initial init)] expr [if guard]))
Accumulates expr
into a list. ´bindingis only accesible in the final-expression. The list is in the same order as the loop bodies were evaluated. If
initialis given that will be used as the tail of the accumulated results. It defaults to
’()`.
(:acc binding (listing-reverse [(:initial init)] expr [if guard]))
The same as listing
but the resulting list in in reverse order. If the order of the resulting list does not matter, this will be faster than the regular listing as it will not preform any reverse at the end.
(:acc binding (appending [(:initial init)] expr [if guard]))
expr
evaluates to a list that is then appended to the accumulated result.
Many accumulating clauses support an :if
form. If such a clause is given, accumulation will only happen if the guard clause returns true.
(:acc binding (listing [(:initial init)] expr [(:if guard)]))
Accumulates expr
into a list. ´bindingis only accesible in the final-expression. The list is in the same order as the loop bodies were evaluated. If
initialis given that will be used as the tail of the accumulated results. It defaults to
’()`.
(:acc binding (listing-reverse [(:initial init)] expr [(:if guard)]))
The same as listing
but the resulting list in in reverse order. If the order of the resulting list does not matter, this will be faster than the regular listing as it will not preform any reverse at the end.
(:acc binding (appending [(:initial init)] expr [(:if guard)]))
expr
evaluates to a list that is then appended to the accumulated result.
(loop ((:for elt (in-list '((1 2) (3 4)))) (:acc acc (appending (:initial '(0)) elt))) => acc) ;; => (0 1 2 3 4) -
(:acc binding (appending-reverse [(:initial init)] expr [if guard]))
expr
evaluates to a list that is then consed element by element onto the already accumulated results. The default initial value is '()
.
(:acc binding (appending-reverse [(:initial init)] expr [(:if guard)]))
expr
evaluates to a list that is then consed element by element onto the already accumulated results. The default initial value is '()
.
(loop ((:for elt (in-list '((1 2) (3 4)))) (:acc acc (appending-reverse (:initial '(0)) elt))) => acc) ;; => (4 3 2 1 0) -
(:acc binding (summing [(:initial init)] expr [(if guard)]))
Adds the result of expr
together using +
. The default initial value is 0.
(:acc binding (multiplying [(:initial init)] expr [(if guard)]))
Multiplies the result of expr
using *
. The default initial value is 1.
(:acc binding (hashing [(:initial init)] key value [(if guard)]))
Adds the mapping (key => value)
to the hashtable binding
using equal?-hashing. The initial hash table is an empty hash-table. binding
is bound to the hash table throughout the loop, and its content can be mutated in the loop body.
(:acc binding (hashving [(:initial init)] key value [(if guard)]))
Adds the mapping (key => value)
to the hashtable binding
using eqv?-hashing. The initial hash table is an empty hash-table. binding
is bound to the hash table throughout the loop, and its content can be mutated in the loop body.
(:acc binding (hashqing [(:initial init)] key value [(if guard)]))
Adds the mapping (key => value)
to a hashtable using eq?-hashing. The initial hash table is an empty hash-table.binding
is bound to the hash table throughout the loop, and its can be mutated in the loop body.
(:acc binding (summing [(:initial init)] expr [(:if guard)]))
Adds the result of expr
together using +
. The default initial value is 0.
(:acc binding (multiplying [(:initial init)] expr [(:if guard)]))
Multiplies the result of expr
using *
. The default initial value is 1.
(:acc binding (hashing [(:initial init)] key value [(:if guard)]))
Adds the mapping (key => value)
to the hashtable binding
using equal?-hashing. The initial hash table is an empty hash-table. binding
is bound to the hash table throughout the loop, and its content can be mutated in the loop body.
(:acc binding (hashving [(:initial init)] key value [(:if guard)]))
Adds the mapping (key => value)
to the hashtable binding
using eqv?-hashing. The initial hash table is an empty hash-table. binding
is bound to the hash table throughout the loop, and its content can be mutated in the loop body.
(:acc binding (hashqing [(:initial init)] key value [(:if guard)]))
Adds the mapping (key => value)
to a hashtable using eq?-hashing. The initial hash table is an empty hash-table.binding
is bound to the hash table throughout the loop, and its can be mutated in the loop body.
(:acc binding [index] (vectoring expr [(:length len) [(:fill fill)]]))
Accumulates the result of expr
into a vector. If len
and fill
is given the vector will be at most len
elements long and any unfilled indexes will contain the element fill
. The loop will exit when len
elements have been accumulated.
If length
is not given, the vector will be expanded as required.
A vectoring clause adds an implicit (:break (= index len))
after the vectoring clause. Once the last element of the vector is filled, the loop will stop and no subsequent clauses or body will be executed.