views:

59

answers:

1

How can I create a library called rnrs-modified which will make the following code display "Hello, world!"...?

#!r6rs
(import (rnrs-modified))
(display set!)

or even this would be good (arguably better, actually):

#!r6rs
(import (rnrs) (modified)) ;or (import (modified) (rnrs))
(display set!)

Essentially I want to be able to redefine syntactic keywords (let, lambda, set!, etc) in a library, and then import that library into another library or a top-level program and use those redefined keywords.

However I keep getting this:

module: identifier already imported from a different source in:
  set!
  (lib "rnrs/main.ss")
  (lib "rnrs-modified/main.ss")

The code I'm using for rnrs-modified is:

#!r6rs
(library (rnrs-modified)
         (export (rename (f set!)))
         (import (rnrs))
         (define f "Hello, world!"))

Any ideas?


Update: I found this for 'mzscheme modules'. It's not for r6rs scheme, but the functionality it offers is basically exactly what I'm looking for. How can I do provide all-from-except in r6rs scheme?

+1  A: 

R6RS lends itself more towards achieving your goal by identifying the library that you want to customize, excluding the parts you want to customize, and then defining those parts in your own library. Here is an example:

myrnrs.sls

(library
 (myrnrs)

 (export set!)

 (import
  (except (rnrs) set!)
  (rename (rnrs) (set! rnrs-set!)))

 (define set! "Hello, world."))

test.scm

(import
 (except (rnrs) set!)
 (myrnrs))
 (display set!)(newline)    

Unfortunately there is nothing like all-from-except like we have in Racket; so you could create a library that redefines set!, but you would have to import rnrs and then type in the exports for all of those bindings in addition to redefining set!. You read more about here; ironically I wanted to create a library without set!, too.

grettke
+1, Thanks for answering - I was afraid this might be the case :(. This kind of sucks. How valid an option do you think it is to add exports for all other bindings? I could probably automate the task by parsing the documentation or something, so it's possible. But in my experience, hardcoded solutions like that are usually bad, and break easily. What do you think? Also, any idea why such a restrictive library system was chosen for r6rs? Edit: I actually ran accross that link while doing research earlier. Small world :P
Cam
1. The R6RS standard won't change; so once you get the exports correct you will be set for life.2. I don't know why it is that way. From one perspective, R6RS had a goal of defining a standard for the common features found across different Scheme systems today so maybe those were the subset of module features that were common? In the last R6RS code I looked, the author painfully manually exported loads and loads of his own functions. all-from-* seems like a no-brainer.
grettke