Made => implicit if we have accumulators

If there are accumulators, their final values will be returned if no
final-expr is given.

(loop ((:for a (up-from 1 11))
       (:acc lst (listing (* a a))))
  => lst)

becomes simply:

(loop ((:for a (up-from 1 11))
       (:acc lst (listing (* a a)))))
This commit is contained in:
Linus 2021-05-18 20:39:37 +02:00
parent 7a1137e579
commit 93134a1b21
2 changed files with 36 additions and 29 deletions

View file

@ -56,14 +56,10 @@
(define-syntax %loop
(syntax-rules (=>)
((%loop o () => expr body ...)
(%loop o ((:for ensure-once (up-from 0 1))) => expr body ...))
(syntax-rules ()
((%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 () body ...)
(%loop o name ((:for ensure-once (up-from 0 1))) body ...))
((%loop o (clauses ...) body ...)
(ensure-for-clause #f () (clauses ...) o
@ -125,8 +121,12 @@
(syntax-rules (=> :for :acc :when :unless :break :final :do :bind :subloop)
((_ orig name l a v c r f ff user () => expr . body)
(emit orig name l a v c r f ff user expr . body))
((_ orig name l a v c r f ff user () . body)
(emit orig name l a v c r f ff user (if #f #f) . body))
((_ orig name l a v c r () ff user () . body)
(emit orig name l a v c r () ff user (if #f #f) . body))
;; If we have no final-expr, but we have final bindings, we return those.
((_ orig name l a v c r ((final-binding expr) ...) ff user () . body)
(emit orig name l a v c r ((final-binding expr) ...) ff user (values final-binding ...) . body))
;; user bindings
((_ orig name l a v c r f ff ((cur-ul ...) . ul-rest) ((:bind (id id* ... expr) ...) clauses ...) . body)