[r6rs-discuss] [Formal] body should allow mixing declarations with expressions

From: Lauri Alanko <la>
Date: Mon Mar 12 11:31:10 2007

On Sun, Mar 11, 2007 at 01:13:13PM -0700, Per Bothner wrote:
> Scheme should allow expressions and declarations to be mixed in
> all bodies, not just top-level bodies.

I agree. I always tend to use macros that allow this, or if not, then
I just wrap everything inside a let* or letrec*.

There is a question of how this should be translated. If we have:

(let ()
  (define a (foo))
  (define b (bar))
  (baz)
  (define c (quux))
  (quuux))

Then should it be translated as

(let ()
  (letrec* ((a (foo))
            (b (bar)))
    (baz)
    (letrec* ((c (quux)))
      (quuux))))

or

(let ()
  (letrec* ((a (foo))
            (b (bar))
            (dummy (baz))
            (c (quux)))
    (quuux)))
?

The first way would allow redefining the same variable multiple times
in a body, but I'd prefer the latter alternative, so that all
expressions and definitions directly inside a body use the same
scope. Moreover, I think that a definition should be allowed as the
final element of a body. The body of the resulting letrec* expression
would then be (unspecified).


Lauri
Received on Mon Mar 12 2007 - 11:31:01 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC