Added annotations for code highlighting

This commit is contained in:
Linus 2021-05-18 18:14:25 +02:00
parent 2c323be362
commit 20471c01c2

View file

@ -76,20 +76,21 @@ Due to clause reordering, positional updates are not supported. If you want to u
### Lexical order of clauses
(loop ((:for a (in-list 1 2 3)
(:bind b (expensive-operation1 a))
(:when (test? b))
(:bind c (expensive-operation2 b))
(:when test2? c)
(:acc acc (listing c))))
=> acc)
``` scheme
(loop ((:for a (in-list 1 2 3)
(:bind b (expensive-operation1 a))
(:when (test? b))
(:bind c (expensive-operation2 b))
(:when test2? c)
(:acc acc (listing c))))
=> acc)
```
### Loop naming to make it "fold right"
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))))
=> '()
(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
```
``` scheme
;; Shamelessly stolen from Taylor Campbell's foof-loop documentation
(define (partition list predicate)
(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
```
``` scheme
(loop name ((:for elt pair (in-list '(1 2 3))))
=> '()
(if (null? (cdr pair))
@ -175,7 +176,7 @@ The iterative fibonacci loop is weird to write using for/fold. goof fixes this:
### Simple forms
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)))
a)
;; => (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:
```
``` scheme
> ,opt (loop ((:for a (in-list '(1 2 3 4)))
(:when (even? a))
(:acc acc (listing a)))