Update readme to reflect recent changes.wq
This commit is contained in:
parent
2c182da570
commit
a3244a065a
1 changed files with 17 additions and 17 deletions
34
README.md
34
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:
|
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))
|
(loop ((a (in 0 b))
|
||||||
(:for b (in 1 (+ a b)))
|
(b (in 1 (+ a b)))
|
||||||
(:for count (up-from 0 (to 1000)))
|
(count (up-from 0 (to 1000)))
|
||||||
(:acc acc (listing b)))
|
(acc (listing b)))
|
||||||
=> acc
|
=> acc
|
||||||
(display b) (newline))
|
(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:
|
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)))
|
(define lst '((1 2) dud (3 4) (5 6)))
|
||||||
(loop ((:for a (in-list lst))
|
(loop ((a (in-list lst))
|
||||||
(:when (pair? a))
|
:when (pair? a)
|
||||||
(:for b (in-list a))
|
(b (in-list a))
|
||||||
(:acc acc (summing b)))
|
(acc (summing b)))
|
||||||
=> acc)
|
=> 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:
|
Accumulators can be in any of the loop's stages:
|
||||||
|
|
||||||
```
|
```
|
||||||
(loop ((:for a (in-list '(1 2 3)))
|
(loop ((a (in-list '(1 2 3)))
|
||||||
(:acc aa (summing a))
|
(aa (summing a))
|
||||||
:subloop
|
:subloop
|
||||||
(:for b (up-from a (to (+ a 2))))
|
(b (up-from a (to (+ a 2))))
|
||||||
(:acc ab (listing b)))
|
(ab (listing b)))
|
||||||
=> (values aa ab))
|
=> (values aa ab))
|
||||||
;; => (values 6 (1 2 2 3 3 4))
|
;; => (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:
|
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)
|
(if (odd? a)
|
||||||
(cons (* a (- a)) (loopy-loop))
|
(cons (* a (- a)) (loopy-loop))
|
||||||
|
@ -87,9 +87,9 @@ Named updates also work.
|
||||||
```
|
```
|
||||||
;; Shamelessly stolen from Taylor Campbell's foof-loop documentation
|
;; Shamelessly stolen from Taylor Campbell's foof-loop documentation
|
||||||
(define (partition list predicate)
|
(define (partition list predicate)
|
||||||
(loop continue ((:for element (in-list list))
|
(loop continue ((element (in-list list))
|
||||||
(:acc satisfied (in '()))
|
(satisfied (folding '()))
|
||||||
(:acc unsatisfied (in '())))
|
(unsatisfied (folding '())))
|
||||||
=> (values (reverse satisfied)
|
=> (values (reverse satisfied)
|
||||||
(reverse unsatisfied))
|
(reverse unsatisfied))
|
||||||
(if (predicate element)
|
(if (predicate element)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue