Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

in search for a less-ugly name for a macro

14 views
Skip to first unread message

Marco Maggi

unread,
Jul 22, 2011, 1:36:00 AM7/22/11
to
Ciao,

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

John Cowan

unread,
Jul 22, 2011, 2:22:28 AM7/22/11
to
On Jul 22, 1:36 am, Marco Maggi <ma...@maggi.invalid> wrote:

> 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)

Marco Maggi

unread,
Jul 22, 2011, 3:33:06 AM7/22/11
to
John Cowan wrote:

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 Němec

unread,
Jul 22, 2011, 6:52:33 AM7/22/11
to
FWIW, I don't see what's more ugly about `begin0-let' than `begin0'
itself, so, given the latter, the former seems just fine to me. At least
it's quite clear (provided one already knows what `begin0' does).

Štěpán

0 new messages