Updated documentation to reflect previous change.

This commit is contained in:
Linus 2021-03-18 12:43:56 +01:00
parent 5847bd21d4
commit 78aed79463
2 changed files with 19 additions and 3 deletions

View file

@ -4,6 +4,7 @@
<title>Goof-loop</title>
<author email="linus.internet@fastmail.se">Linus Björnstam</author>
</metadata>
<section title="Preface">
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 @@
<subsection title=":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.
<spec>
<syntax name="in">
@ -218,13 +222,17 @@
</example>
Will print all fibonacci numbers below 20.
`binding` is a loop variable and can thus be changed using named updates.
</syntax>
<syntax name="up-from">
<form>(:for binding (up-from start [(to bound)] [(by step)]))</form>
<form>(:for binding (up-from start [(:to bound)] [(:by step)]))</form>
<form>(:for binding (up-from start [bound [by]]))</form>
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.
</syntax>
<syntax name="down-from">
@ -232,6 +240,8 @@
<form>(:for binding (down-from start [bound [by]]))</form>
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.
</syntax>
<syntax name="in-list">