Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top