Added annotations for code highlighting
This commit is contained in:
parent
2c323be362
commit
20471c01c2
1 changed files with 14 additions and 13 deletions
27
README.md
27
README.md
|
|
@ -76,20 +76,21 @@ Due to clause reordering, positional updates are not supported. If you want to u
|
||||||
|
|
||||||
### Lexical order of clauses
|
### Lexical order of clauses
|
||||||
|
|
||||||
(loop ((:for a (in-list 1 2 3)
|
``` scheme
|
||||||
(:bind b (expensive-operation1 a))
|
(loop ((:for a (in-list 1 2 3)
|
||||||
(:when (test? b))
|
(:bind b (expensive-operation1 a))
|
||||||
(:bind c (expensive-operation2 b))
|
(:when (test? b))
|
||||||
(:when test2? c)
|
(:bind c (expensive-operation2 b))
|
||||||
(:acc acc (listing c))))
|
(:when test2? c)
|
||||||
=> acc)
|
(:acc acc (listing c))))
|
||||||
|
=> acc)
|
||||||
|
```
|
||||||
|
|
||||||
### Loop naming to make it "fold right"
|
### Loop naming to make it "fold right"
|
||||||
|
|
||||||
You can of course still have a larger control of when to loop by naming your loop:
|
You can of course still have a larger control of when to loop by naming your loop:
|
||||||
|
|
||||||
```
|
``` scheme
|
||||||
(loop loopy-loop ((:for a (up-from 1 (to 11))))
|
(loop loopy-loop ((:for a (up-from 1 (to 11))))
|
||||||
=> '()
|
=> '()
|
||||||
(if (odd? a)
|
(if (odd? a)
|
||||||
|
|
@ -101,7 +102,7 @@ You can of course still have a larger control of when to loop by naming your loo
|
||||||
|
|
||||||
### Named updates
|
### Named updates
|
||||||
|
|
||||||
```
|
``` scheme
|
||||||
;; 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 ((:for element (in-list list))
|
||||||
|
|
@ -121,7 +122,7 @@ You can of course still have a larger control of when to loop by naming your loo
|
||||||
|
|
||||||
The iterator protocol allows exposing the loop variables
|
The iterator protocol allows exposing the loop variables
|
||||||
|
|
||||||
```
|
``` scheme
|
||||||
(loop name ((:for elt pair (in-list '(1 2 3))))
|
(loop name ((:for elt pair (in-list '(1 2 3))))
|
||||||
=> '()
|
=> '()
|
||||||
(if (null? (cdr pair))
|
(if (null? (cdr pair))
|
||||||
|
|
@ -175,7 +176,7 @@ The iterative fibonacci loop is weird to write using for/fold. goof fixes this:
|
||||||
### Simple forms
|
### Simple forms
|
||||||
I also provide simplified forms for many common operations. Omitting :for is allowed, and :acc clauses are not allowed.
|
I also provide simplified forms for many common operations. Omitting :for is allowed, and :acc clauses are not allowed.
|
||||||
|
|
||||||
```
|
``` scheme
|
||||||
(loop/list ((a (up-from 0 3)))
|
(loop/list ((a (up-from 0 3)))
|
||||||
a)
|
a)
|
||||||
;; => (0 1 2)
|
;; => (0 1 2)
|
||||||
|
|
@ -214,7 +215,7 @@ I also provide simplified forms for many common operations. Omitting :for is all
|
||||||
|
|
||||||
Speed is good. Despite the rather involved expansion you can see in the documentation, due to inlining and dead-code elimination, the actual expansion shows some good code:
|
Speed is good. Despite the rather involved expansion you can see in the documentation, due to inlining and dead-code elimination, the actual expansion shows some good code:
|
||||||
|
|
||||||
```
|
``` scheme
|
||||||
> ,opt (loop ((:for a (in-list '(1 2 3 4)))
|
> ,opt (loop ((:for a (in-list '(1 2 3 4)))
|
||||||
(:when (even? a))
|
(:when (even? a))
|
||||||
(:acc acc (listing a)))
|
(:acc acc (listing a)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue