More parentheses

I have changed my mind about the clause forms. They should, with the
exception of :subloop, be parethesised: :when test => (:when test).
This commit is contained in:
Linus 2021-02-18 21:19:12 +01:00
parent a545c1cbd7
commit 7b3814c430
2 changed files with 53 additions and 36 deletions

View file

@ -18,7 +18,7 @@ Compared to foof-loop, some things are added. Apart from minor syntactic changes
```
(define lst '((1 2) dud (3 4) (5 6)))
(loop ((:for a (in-list lst))
:when (pair? a)
(:when (pair? a))
(:for b (in-list a))
(:acc acc (summing b)))
=> acc)
@ -111,12 +111,12 @@ I also provide simplified forms for many common operations. Omitting :for is all
a)
;; => 24
(loop/first ((a (in-list '(a b c 3 4 d))) :when (integer? a))
(loop/first ((a (in-list '(a b c 3 4 d))) (:when (integer? a)))
(display a)
a)
;; => displays 3 and returns 3.
(loop/last ((a (in-list '(a b c d e f))) :break (eq? a 'e))
(loop/last ((a (in-list '(a b c d e f))) (:break (eq? a 'e)))
a)
;; => 'd
@ -194,7 +194,7 @@ Speed is good. Despite the rather involved expansion above, due to dead-code eli
```
> ,opt (loop ((:for a (in-list '(1 2 3 4)))
:when (even? a)
(:when (even? a))
(:acc acc (listing a)))
=> acc)
$1 = (let loopy-loop ((cursor-1 '()) (cursor '(1 2 3 4)))
@ -207,13 +207,13 @@ $1 = (let loopy-loop ((cursor-1 '()) (cursor '(1 2 3 4)))
;; loop/list, being less general, produces faster code that can be more easily unroled and optimized.
> ,opt (loop/list ((a (in-list '(1 2 3 4)))
:when (even? a))
(:when (even? a)))
a)
$2 = (list 2 4)
;; Removing the opportunity to completely remove the loop
> ,opt (loop/list ((a (in-list (read)))
:when (even? a))
(:when (even? a)))
a)
$5 = (let loopy-loop ((cursor (read)))