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

Keith Wright r6rsguy at free-comp-shop.com
Sat Aug 25 03:15:29 EDT 2007


> From: AndrevanTonder <andre at het.brown.edu>
> 
> On Fri, 24 Aug 2007, Keith Wright wrote:
> 
> > If this interpretation is correct, then the above definition
> > of |sqrt| is legal in a <body>, even if that <body> imports
> > the standard definition of |sqrt|.
> 
> With one caveat.  Section 7.1 says:
> 
>    ... no identifier can be imported multiple times, defined
>    multiple times, or both defined and imported.

That's page 23, right column, for those who are following
along at home.

That caveat is in the section "Library Form", so does it
apply also to a top-level program?

We have <body>, <library body>, and <top-level body>, and
I have not totally figured out the relation between them.
For example, is it an error that the second paragraph of
section 10 mentions <body> and <library body>, but not
<top-level body>?

> So yes, you can import the binding of standard sqrt into a
> library that defines its own sqrt if you rename the former
> on import like this:
> 
>    (library (foo)
>      (export ---)
>      (import (rename (rnrs) (sqrt rnrs:sqrt)))
>      (define (sqrt x) ---)
>      ---)

If it takes all that extra typing just to make it work like
it used to, perhaps Elf's criticism has some merit.

I just want to be able to define my own |sqrt| without
even knowing whether or not there is a built-in one.

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

After all, I can say

  (let ()
    (define x 7)
    (let ()
      (define x 22)
      x))

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

> By the way, this also resolves an inconsistency in R5RS where
> toplevel redefinitions would affect user-defined procedures
> but were required not to affect standard procedures.

Again, already fixed by the new scope, if by "user-defined" you
mean "defined in top-level".  A definition _should_ affect
uses within its scope and not those in an outer scope.

By the way, I have not been able to find any place where it
says that the (rnrs base) library is imported automatically.
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?

  -- Keith





More information about the r6rs-discuss mailing list