(extend-syntax (gathering)
;; Because we currently lack multiple values in Scheme, the one-gatherer
;; case of GATHERING returns the value of that accumulation but the
;; multiple-gatherer case returns a LIST of the values of the
;; accumulations. This discontinuity is ugly, but convenient for the
;; usual case.
( (gathering ((var expr))
body more-body ...)
(with ((gatherer-name (gensym)))
(let* ((gatherer-name expr)
(var (car gatherer-name))
(gather (lambda (value accumulator)
(accumulator value))))
body
more-body ...
((cadr gatherer-name)))))
( (gathering ((var expr) ...)
body more-body ...)
(with (((gatherer-name ...) (map (lambda (ignore) (gensym))
'(var ...))))
(let* ((gatherer-name expr) ...
(var (car gatherer-name)) ...
(gather (lambda (value accumulator)
(accumulator value))))
body
more-body ...
(list ((cadr gatherer-name)) ...)))))