[r6rs-discuss] Why does begin not have a body?

From: Jeff Read <bitwize>
Date: Fri Oct 13 15:25:48 2006

On 10/13/06, Alan Watson <alan_at_alan-watson.org> wrote:

> Why make this distinction? I know it is traditional in Scheme, but it
> seems arbitrary.
>

Bodies are evaluated within a new lexical scope. BEGIN is a sequencing
primitive -- it does not introduce its own lexical scope.

When used as a form in a <body>, the contents of the BEGIN are spliced
right into the <body>. This means that expressions like (lambda (x)
(begin (define bar ...) (foo x)) (define baz ...) bar) will break
because they violate the rule that internal definitions can only occur
at the beginning part of a body (after the declarations).

In order for BEGIN to work the way you would like, it would need to
introduce its own lexical scope, which would eliminate some of its
more useful aspects (like sequencing a bunch of definitions in a macro
that introduces many definitions at once). You could put this
functionality back of course, but then BEGIN will behave confusingly,
introducing new lexical scope at some times but not at others.

If it bothers you that much, simply use (let () ...).

--Jeff
Received on Fri Oct 13 2006 - 15:25:39 UTC

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