From 78aed79463b7cf7c14cd8308e79477908116ca16 Mon Sep 17 00:00:00 2001 From: Linus Date: Thu, 18 Mar 2021 12:43:56 +0100 Subject: [PATCH] Updated documentation to reflect previous change. --- documentation/doc.html | 10 ++++++++-- documentation/doc.xml | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/documentation/doc.html b/documentation/doc.html index c66b3a2..4d2b328 100644 --- a/documentation/doc.html +++ b/documentation/doc.html @@ -29,6 +29,8 @@ loop-clause = (:for id id* ... seq-expr) | (:acc id id* ... seq-expr) + | (:let id expr) + | (:let* id expr) | (:when guard-expr) | (:unless guard-expr) | (:break break-expr) @@ -103,13 +105,17 @@
Scheme syntax: loop/and
(loop/and (clauses ...) body ...)

If all evaluated bodies return truthy, return the result of the last evaluated body. If any body returns #f, stop iteration and return #f. If no body is evaluated, #t is returned.

Scheme syntax: loop/or
(loop/or (clauses ...) body ...)

If any evaluated body returns truthy, stop iteration and return the result of that body. If no body returns truthy, return #f. If no body is evaluated, return #f.

Scheme syntax: loop/list/parallel
(loop/list/parallel (clauses ...) body ...)

Like loop/list, but evaluates each body in parallel.

-

:for-clauses

Scheme syntax: in
(:for binding (in start [update [stop]]))

Binds a loop variable to binding. It’s first value is start. It is updated by the update expression, or is left unchanged if no such expression is present. If a stop expression is provided, it will be evaluated before each loop body. If the stop expression returns true, the iteration will be considered exhausted.

+

:for-clauses

A :for clause specifies a number of identifiers that are bound to a value from a sequence. (:for i (up-from 0 10))) will bind a to all integers between 0 and 10 (excluseve) in order. The first time the loop is executed, it is bound to 0, then 1, then 2, and so on. Some loops has support for exposing their loop variables to the user. In the case of (:for elt pair (in-list lst)), elt will be bound to the car of pair, whereas pair will be bound to the loop variable used by in-list to hold the current position of the list.

+
Scheme syntax: in
(:for binding (in start [update [stop]]))

Binds a loop variable to binding. It’s first value is start. It is updated by the update expression, or is left unchanged if no such expression is present. If a stop expression is provided, it will be evaluated before each loop body. If the stop expression returns true, the iteration will be considered exhausted.

 (loop ((:for a (in 0 b)) (:for b (in 1 (+ a b) (> b 20))))
   (display b) (newline))
         

Will print all fibonacci numbers below 20.

-
Scheme syntax: up-from
(:for binding (up-from start [(to bound)] [(by step)]))
(:for binding (up-from start [bound [by]]))

Binds binding to the number start up to bound (exclusive!) by step. If no bound is given, it will yield values indefinitely. The second shorter form will not allow unbounded iteration if a step other than 1 is wanted.

+

binding is a loop variable and can thus be changed using named updates.

+
Scheme syntax: up-from
(:for binding (up-from start [(:to bound)] [(:by step)]))
(:for binding (up-from start [bound [by]]))

Binds binding to the number start up to bound (exclusive!) by step. If no bound is given, it will yield values indefinitely. The second shorter form will not allow unbounded iteration if a step other than 1 is wanted.

+

binding is a loop variable and can thus be changed using named updates.

Scheme syntax: down-from
(:for binding (down-from start [(to bound)] [(by step)])
(:for binding (down-from start [bound [by]]))

Binds binding to the number (- start 1) down to bound (inclusive!) by step. If no bound is given, it will yield values indefinitely. The second shorter form will not allow unbounded iteration if a step other than 1 is wanted.

+

binding is a loop variable and can thus be changed using named updates.

Scheme syntax: in-list
(:for binding [pair] (in-list expr [by])

Binds binding to the car of the loop variable pair. pair is advanced by applying the procedure by to it (defaulting to cdr). The iteration stops when pair is the empty list.

Scheme syntax: in-lists
(:for binding [pairs] (in-lists expr [by])

Works the same as in-list, but expr must evaluate to a list of lists. binding is bound to the car of those lists, and they are advanced by by, defaulting to cdr.

Scheme syntax: in-vector
(:for binding [index] (in-vector expr [low [high]]))

Binds binding to all elements in the vector produced by expr in order from low to high. low defaults to 0 and high defaults to the last index of the vector.

diff --git a/documentation/doc.xml b/documentation/doc.xml index 48f2a8b..74ca8ee 100644 --- a/documentation/doc.xml +++ b/documentation/doc.xml @@ -4,6 +4,7 @@ Goof-loop Linus Björnstam +
We have all had the thought. *Why oh why are not all our problems solved by a nice recursive algorithm over a list?*. We see a neat problem. We smile and think about all the nice things we shall do right after finishing off this little tidbit, this delicious little bite of a problem. Then we scrape the surface. Under there is a jungle of state. Suddenly our little recursive list-mangling is not enough. To defeat the anxiety rising within us, we quickly write something using map, filter, zip and reduce. We test it. We smile again. We test it on real world data. The smile stiffens. The little bite has turned in to an o(n²) turd. @@ -53,6 +54,8 @@ loop-clause = (:for id id* ... seq-expr) | (:acc id id* ... seq-expr) + | (:let id expr) + | (:let* id expr) | (:when guard-expr) | (:unless guard-expr) | (:break break-expr) @@ -206,6 +209,7 @@ + A :for clause specifies a number of identifiers that are bound to a value from a sequence. `(:for i (up-from 0 10)))` will bind a to all integers between 0 and 10 (excluseve) in order. The first time the loop is executed, it is bound to 0, then 1, then 2, and so on. Some loops has support for exposing their loop variables to the user. In the case of `(:for elt pair (in-list lst))`, `elt` will be bound to the car of `pair`, whereas `pair` will be bound to the loop variable used by `in-list` to hold the current position of the list. @@ -218,13 +222,17 @@ Will print all fibonacci numbers below 20. + + `binding` is a loop variable and can thus be changed using named updates. -
(:for binding (up-from start [(to bound)] [(by step)]))
+
(:for binding (up-from start [(:to bound)] [(:by step)]))
(:for binding (up-from start [bound [by]]))
Binds `binding` to the number `start` up to `bound` (exclusive!) by `step`. If no `bound` is given, it will yield values indefinitely. The second shorter form will not allow unbounded iteration if a `step` other than `1` is wanted. + + `binding` is a loop variable and can thus be changed using named updates.
@@ -232,6 +240,8 @@
(:for binding (down-from start [bound [by]]))
Binds `binding` to the number `(- start 1)` down to `bound` (inclusive!) by `step`. If no `bound` is given, it will yield values indefinitely. The second shorter form will not allow unbounded iteration if a `step` other than `1` is wanted. + + `binding` is a loop variable and can thus be changed using named updates.