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,6 +76,7 @@ Due to clause reordering, positional updates are not supported. If you want to u
### Lexical order of clauses ### Lexical order of clauses
``` scheme
(loop ((:for a (in-list 1 2 3) (loop ((:for a (in-list 1 2 3)
(:bind b (expensive-operation1 a)) (:bind b (expensive-operation1 a))
(:when (test? b)) (:when (test? b))
@ -83,13 +84,13 @@ Due to clause reordering, positional updates are not supported. If you want to u
(:when test2? c) (:when test2? c)
(:acc acc (listing c)))) (:acc acc (listing c))))
=> acc) => 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)))