1

I have a file open in editor and a scheme running in a console window next to it. Here is what is in the file:

(import (rnrs))
(define THIS "Hello")
(display THIS) ;; does not work if loaded

I edit definitions in a file, save it, then switch to scheme window and execute

(load "c:\\path\\to\\filename.ss")

I see "Hello" in the output, but when I try to access THIS -- THIS is undefined.

I am using IronScheme (if it is relevant) and I am new to scheme in general, so how do I change definitions in a session by modifying and re-reading a file?

nsg
  • 539
  • 1
  • 6
  • 18

1 Answers1

4

There is no function load in R6RS; apparently IronScheme has one. You should check their documentation but what is most likely happening is that the loaded file is read, compiled and then evaluated in its own environment. The identifier THIS will thus be defined in that environment. Apparently, you don't have access to that environment. Again, check the documentation.

As IronScheme claims to be R6RS compliant, the proper way to achieve your goal is:

;;lib-for-this.ss
(library (lib-for-this)
  (export THIS)
  (import (rnrs))
  (begin
    (define THIS "hello")
    (display THIS)))

Then when you want to use THIS:

> (import (lib-for-this))
hello         ;; <= from `display` most likely
> THIS
"hello"
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Is there a special place where I have to place the file and name it for this to work? Alternatively, is there way to import library using filename (string)? – nsg Feb 27 '14 at 16:38
  • It will depend on your Scheme. There might be a shell environment variable, maybe IRON_SCHEME_LIBRARY_DIR, where libraries will be located. I believe the library name and the filename need to be identical/consistent. – GoZoner Feb 27 '14 at 17:49
  • 1
    @GoZoner: There is a `library-path` parameter you can use to control that. – leppie Jan 23 '15 at 10:13