I am using the macro BEGIN0 defined in the R6RS document
(Appendix A ``Formal semantics'', visible in the PDF version
but not in the HTML one):
(define-syntax begin0
(syntax-rules ()
((_ ?expr0 ?expr ...)
(call-with-values
(lambda () ?expr0)
(lambda args
?expr ...
(apply values args))))))
but sometimes I need the result of ?EXPR0 in the subsequent
expressions, so I defined:
(define-syntax begin0-let
(syntax-rules ()
((_ (((?var0 ...) ?expr0)
((?var ...) ?expr)
...)
?form0 ?form ...)
(let-values (((?var0 ...) ?expr0)
((?var ...) ?expr)
...)
?form0 ?form ...
(values ?var0 ...)))
((_ ((?var0 ?expr0)
(?var ?expr)
...)
?form0 ?form ...)
(let ((?var0 ?expr0)
(?var ?expr)
...)
?form0 ?form ...
?var0))))
the name BEGIN0-LET is truly ugly, but I cannot come up with
something less ugly. If someone could suggest a better
one... :-)
TIA
--
Marco Maggi
> the name BEGIN0-LET is truly ugly, but I cannot come up with
> something less ugly. If someone could suggest a better
> one... :-)
It seems kind of silly to have a specialized macro to do what amounts
to this, modulo multiple values:
(let ((x expr0)
expr1
...
x)
He! He! Happy for you to have better code-reading
capabilities than me. I find useful to tell the reader at
the beginning that the purpose of the form:
(begin0-let ((x (some-expr)))
(stuff)
(do-something-with x)
(stuff))
is to return the result of (SOME-EXPR). When I use
BEGIN0-LET in my code, it is almost always in a situation
like:
(define (doit)
(do-stuff)
(begin0-let ((x (some-expr)))
(side-effect)
(update-state-with x)
(side-effect)))
that is: the computation is "finished" with the evaluation
of (SOME-EXPR). While there is no way to enforce this
semantics, I find useful to give a hint to the reader about
this.
--
Marco Maggi
Štěpán