Hi folks,
I'm new to Scheme and exploring Chez and Racket, both of which
have been awesome so far!
I'm trying to see if there is a way to dynamically reload code
from a library in Chez scheme (AKA hot reload). The parallel in
Racket would be the use of `dynamic-require` and
`dynamic-rerequire`.
I seem to be able to do this in the REPL:
> (load "reload-lib.ss")
> (import (reload-lib))
> (foo)
Foo!
Then if I change `foo` in `reload-lib.ss` to print out `Bar!`
instead I get the correct input in the same REPL:
> (load "reload-lib.ss")
> (import (reload-lib))
Bar!
I cannot seem to get the same to work from within a library. For
example, calling `bar` from the following library does not
actually reload `reload-lib.ss`, it just loops printing `Foo!`:
(library (reload-main)
(export bar)
(import (chezscheme))
(define (bar)
(load "reload-lib.ss")
(let ()
(import (reload-lib))
(foo)
(sleep (make-time 'time-duration 0 1))
(bar)))
)
Is there a way to do what I'm trying to do? If I'm way off track,
a nudge in the right direction would be greatly appreciated!
A bit of an aside: I had to put everything in an empty `let` to
get `import` to work. Otherwise I got this:
Exception: invalid context for definition (import (reload-lib)) at line 7, char 5 of reload-main.ss
The Chez scheme docs indicate that `import` can be used in a
local body, which I assumed, perhaps incorrectly, is everything
after the variable and formals in the define form?
Thanks,
Chris