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?
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"