(define old-sin sin)
(define (sin x)
(display "sin(") (write x) (display ")") (newline)
(old-sin x))
where sin is redefined. What is the appropropriate module
system framework to define a new module M where there is
a variable old-sin whose value is the value of the variable
sin from r6rs and a newly defined variable sin with a
different value from the value of the variable sin in r6rs?
And how do I make another module N where there is a variable
sin whose value is the same as the value of the variable sin
in M? I'm willing to have the variable sin in N be the same as
the variable sin in M.
> How do I do overloading in R6RS? I want to do something
> like the following:
>
> (define old-sin sin)
>
> (define (sin x)
> (display "sin(") (write x) (display ")") (newline)
> (old-sin x))
>
> where sin is redefined.
Redefining bindings is not allowed in R6RS. I'm guessing that that
restriction helps compilers a lot.
If you want to use this as some debugging tool, then you're out of luck.
> What is the appropropriate module
> system framework to define a new module M where there is
> a variable old-sin whose value is the value of the variable
> sin from r6rs and a newly defined variable sin with a
> different value from the value of the variable sin in r6rs?
You can however rename bindings on import:
(library (M)
(export sin)
(import (rename (rnrs) (sin old-sin)))
(define (sin x)
(display "sin(") (write x) (display ")") (newline)
(old-sin x)))
> And how do I make another module N where there is a variable
> sin whose value is the same as the value of the variable sin
> in M? I'm willing to have the variable sin in N be the same as
> the variable sin in M.
(library (N)
(export ...)
(import (only M sin)
(rename (rnrs) (sin r6rs-sin)))
...body...)
This makes sin (from M) available and renames the standard sin to
r6rs-sin to avoid name clashes.
Helmut
> Redefining bindings is not allowed in R6RS. I'm guessing that that
> restriction helps compilers a lot.
R5RS allows "define" at top level to create "shadowing"
definitions builtin variables, including those initially
bound to procedures. Having done that, you can assign
to those definitions as you like.
R6RS says you can't "define" anything multiple times in
the same module, can't "import" anything multiple times
in the same module, and can't both "define" and "import"
the same thing. It also pushes many names into libraries
where you can't get them without "import"ing them.
But it does allow you to import them under different
names than they were exported with.
Bear