diff --git a/README.md b/README.md index 136f8b1..d6ac4da 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ WARNING: CURRENTLY PRE-ALPHA. The examples in this document are not consistent w goof-loops aims to be an amalgamation of the racket for loops and Alex Shinn's (chibi-loop). We are many that found racket's for loops a breeze of fresh air, but in the end their most general forms (for/fold and for/foldr) are kinda odd to work with. If you choose not to use those general for loops, you cannot express arbitrary transformations, like say a fibonacci sequence, since for clauses cannot reference eachother. goof-loop tries to fix this: ``` -(loop ((:for a (in 0 b)) - (:for b (in 1 (+ a b))) - (:for count (up-from 0 (to 1000))) - (:acc acc (listing b))) +(loop ((a (in 0 b)) + (b (in 1 (+ a b))) + (count (up-from 0 (to 1000))) + (acc (listing b))) => acc (display b) (newline)) ``` @@ -18,11 +18,11 @@ The above example will display and accumulate the 1000 first fibonacci numbers. Compared to foof-loop, some things are added. Apart from minor syntactic changes, subloops are supported. The best way is to show: ``` -(define lst '((1 2) 'dud (3 4) (5 6))) -(loop ((:for a (in-list lst)) - (:when (pair? a)) - (:for b (in-list a)) - (:acc acc (summing b))) +(define lst '((1 2) dud (3 4) (5 6))) +(loop ((a (in-list lst)) + :when (pair? a) + (b (in-list a)) + (acc (summing b))) => acc) ``` @@ -31,11 +31,11 @@ This will sum all the sublists of lst and produce the result 21. Any :when, :unl Accumulators can be in any of the loop's stages: ``` -(loop ((:for a (in-list '(1 2 3))) - (:acc aa (summing a)) +(loop ((a (in-list '(1 2 3))) + (aa (summing a)) :subloop - (:for b (up-from a (to (+ a 2)))) - (:acc ab (listing b))) + (b (up-from a (to (+ a 2)))) + (ab (listing b))) => (values aa ab)) ;; => (values 6 (1 2 2 3 3 4)) ``` @@ -73,7 +73,7 @@ Due to clause reordering, positional updates are not supported. If you want to u You can of course still have a larger control of your loops: ``` -(loop loopy-loop ((:for a (up-from 1 (to 11)))) +(loop loopy-loop ((a (up-from 1 (to 11)))) => '() (if (odd? a) (cons (* a (- a)) (loopy-loop)) @@ -87,9 +87,9 @@ Named updates also work. ``` ;; Shamelessly stolen from Taylor Campbell's foof-loop documentation (define (partition list predicate) - (loop continue ((:for element (in-list list)) - (:acc satisfied (in '())) - (:acc unsatisfied (in '()))) + (loop continue ((element (in-list list)) + (satisfied (folding '())) + (unsatisfied (folding '()))) => (values (reverse satisfied) (reverse unsatisfied)) (if (predicate element)