Loops without any clauses now run the body at least once.
Small updates to readme.
This commit is contained in:
parent
06a11fc892
commit
685fe86f36
2 changed files with 26 additions and 24 deletions
16
README.md
16
README.md
|
@ -1,7 +1,5 @@
|
|||
# goof-loop - a scheme looping facility
|
||||
|
||||
WARNING: Currently beta-quality.
|
||||
|
||||
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:
|
||||
|
||||
```
|
||||
|
@ -50,19 +48,21 @@ while and until are removed in favour of :break.
|
|||
|
||||
:when and :unless are added to better control when the loop body is executed (and accumulators accumulated)
|
||||
|
||||
with-clauses are removed in favour of (:for var (in init [step [stop]])) or (:acc var (folding init [step])) in case of accumulators.
|
||||
with-clauses are removed in favour of (:for var (in init [step [stop]])) in case of loop clauses, or (:acc var (folding init [step])) in case of accumulators.
|
||||
|
||||
### Regressions compared to foof-loop
|
||||
|
||||
only accumulating clauses are visible in the final-expression. This is due to sequence clauses not being promoted through to outer loops (since they should not keep their state).
|
||||
only accumulating clauses are visible in the final-expression. This is due to sequence clauses not being promoted through to outer loops (since they should not keep their state if an inner loop is exited).
|
||||
|
||||
Due to clause reordering, positional updates are not supported. If you want to update your loop vars, do so using named update (see below).
|
||||
|
||||
### changes
|
||||
|
||||
(with var [init [step [guard]]]) => (:for var (in init [step [stop-expr]])). guard was a procedure, but now it is an expression.
|
||||
(with var [init [step [guard]]]) => (:for var (in init [step [stop-expr]])).
|
||||
|
||||
(with var 10 (- var 1) negative?) => (:for var (in 10 (- var 10) (negative? var)))
|
||||
guard was a procedure, but now it is an expression.
|
||||
|
||||
(with var 10 (- var 1) negative?) => (:for var (in 10 (- var 10) (negative? var)))
|
||||
|
||||
### similarities
|
||||
|
||||
|
@ -242,9 +242,9 @@ $5 = (let loopy-loop ((cursor (read)))
|
|||
```
|
||||
|
||||
## Todo
|
||||
Tests and documentation.
|
||||
Tests!
|
||||
|
||||
Fix the inlining behavious of some of the :for iterators.
|
||||
Finish documentation.
|
||||
|
||||
add generator support for all provided iterators
|
||||
|
||||
|
|
|
@ -45,23 +45,27 @@
|
|||
(include "goof/iterators.scm")
|
||||
|
||||
|
||||
|
||||
(define-syntax loop
|
||||
(syntax-rules ()
|
||||
((loop . rest)
|
||||
(%loop (loop . rest) . rest))))
|
||||
|
||||
(define-syntax %loop
|
||||
(syntax-rules (=>)
|
||||
((loop () => expr body ...)
|
||||
(loop ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||
((loop () body ...)
|
||||
(loop ((:for ensure-once (up-from 0 1))) body ...))
|
||||
((loop name () => expr body ...)
|
||||
(loop name ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||
((loop name () body ...)
|
||||
(loop name ((:for ensure-once (up-from 0 1))) body ...))
|
||||
((loop (clauses ...) body ...)
|
||||
(ensure-for-clause (loop (clauses ...) body ...)
|
||||
((%loop o () => expr body ...)
|
||||
(%loop o ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||
((%loop o () body ...)
|
||||
(%loop o ((:for ensure-once (up-from 0 1))) body ...))
|
||||
((%loop o name () => expr body ...)
|
||||
(%loop o name ((:for ensure-once (up-from 0 1))) => expr body ...))
|
||||
((%loop o name () body ...)
|
||||
(%loop o name ((:for ensure-once (up-from 0 1))) body ...))
|
||||
((%loop o (clauses ...) body ...)
|
||||
(ensure-for-clause o
|
||||
loop-name (clauses ...)
|
||||
body ... (loop-name)))
|
||||
((loop name (clauses ...) . body)
|
||||
(ensure-for-clause (loop name (clauses ...) . body)
|
||||
((%loop o name (clauses ...) . body)
|
||||
(ensure-for-clause o
|
||||
name
|
||||
(clauses ...)
|
||||
. body))))
|
||||
|
@ -441,9 +445,7 @@
|
|||
(define-syntax forify
|
||||
(syntax-rules (:for :acc :when :unless :break :final :subloop :let :let* %acc)
|
||||
((forify o n done-clauses () . body)
|
||||
(cl 1 n
|
||||
(()) (()) (()) (()) (()) () ((() ())) (()) (()) (()) ()
|
||||
done-clauses . body))
|
||||
(%loop o n done-clauses . body))
|
||||
((_ o n (s ...) ((:for c-rest ...) clauses ...) . body)
|
||||
(forify o n (s ... (:for c-rest ...)) (clauses ...) . body))
|
||||
((_ o n (s ...) (:when expr clauses ...) . body)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue