[r6rs-discuss] comment and vote (re-definition)

From: AndrevanTonder <andre>
Date: Sat, 25 Aug 2007 14:40:29 -0400 (EDT)

On Sat, 25 Aug 2007, Keith Wright wrote:

>> ... no identifier can be imported multiple times, defined
>> multiple times, or both defined and imported.
>
> That caveat is in the section "Library Form", so does it
> apply also to a top-level program?

Yes. In 8.1:

   A <top-level body> is like a <library body> (see section 7.1), except
   that definitions and expressions may occur in any order.

> For example, is it an error that the second paragraph of
> section 10 mentions <body> and <library body>, but not
> <top-level body>?

Probably not necessary to mention, given the above quote.

>> The advantage of this over r5rs toplevel redefinitions is of
>> course that other libraries that rely on the standard sqrt will
>> not be broken by the local definition of sqrt in (foo).
>> In this respect library definitions scope just like the
>> internal definitions Scheme has had for a long time.
>
> It seems to me that this is already fixed by the re-writing
> of a <body> into a |letrec*| with the consequent new scope,
> (page 30, top left)
> without a prohibition against defining what has been imported.

You are correct in that this is simply a design choice, and it
would have been possible to allow library-level definitions to
shadow imports locally. I do not know the full reasons behind it,
but perhaps the current more restrictive draft specification makes
it easier to map r6rs libraries onto some existing module systems
than the more permissive alternative. Also, the alternative that
you suggest makes it more difficult to determine the meaning of
things like the following:

   (library (foo)
     (export (car cdr))
     (import (rnrs))
     ---)

With the current draft, the meaning of CAR and CDR is immediately
obvious from the header. With your suggestion, you would need
to read the library body to know what CAR and CDR mean.

> I think I should be able to write a local definition without
> knowing every identifier in every library.

A good implementation (such as my own ;-) will immediately
give you a nice error message, so you do not have to know all
imported identifiers. In any case, how important a fight is
it really to save a few keystrokes in the rare case when you want
to reuse the names of standard bindings? Is it really that much
work to write (except (rnrs) sqrt)? There are so many
more worthwhile things in R5.97RS to fight about ;-)

> By the way, I have not been able to find any place where it
> says that the (rnrs base) library is imported automatically.

It is not.

> I think it should be, since otherwise you can do almost
> nothing. Why retype the import unless you want to do
> something special like rename, prefix, or except?

Besides the ugliness of special treatment for a specific library
(which is admittedly subjective), in many practical cases (e.g.,
providing a restricted sublanguage of (rnrs base) for your students
in a beginning class) what you suggest would actually create more
work and lots of problems.

Andre
Received on Sat Aug 25 2007 - 14:40:29 UTC

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