I'm going through SICP course and as recommended installed mit-scheme. I want to use the REPL together with a scheme file. The reason is because I can add scheme code in the file and then run the commands in REPL. What I have works, but the problem is every time I edit the file, I have to quit terminal and reload the file for REPL to see changes.
Is there a way to reload the file easily or some other way for REPL to see changes from the file?
This my setup:
brew install mit-scheme
code.scm
mit-scheme --load /Users/name/Desktop/code.scm
code.scm
, I have to quit terminal and call this again: mit-scheme --load /Users/name/Desktop/code.scm
System details:
I tried following instructions but this is complicated.
This is what I did:
After this I ran mit-scheme --edit
to open Edwin. I tried to use the code inside of the code.scm
file but it doesn't recognize it. This is the code in code.scm
file:
This is what I want to be able to do:
Notice in this picture, I can type a command, press enter and it automatically runs command. However, I want to be able to call (fib 5)
and it references the function in code.scm
file.
Could someone explain step by step how to do this? It's confusing looking at documentation for scheme websites.
There's actually a built-in load
procedure available in the MIT Scheme REPL.
Evaluating
(load "path/to/file.scm")
causes the Scheme file located at path/to/file.scm to be evaluated at the top level (note that the double quotes around the file name are required).
And, as it turns out, this same function can be used to reload a file. With this in mind, a possible "workflow" might look like this:
(load "path/to/file.scm")
in the REPL(load "path/to/file.scm")
in the REPLUnfortunately, I don't think there is a built-in "reload" procedure. But...if you find yourself reloading a lot (as I imagine you will), you can always quickly write your own at the beginning of a hacking session:
(define (reload)
(load "path/to/file.scm"))
And then just call (reload)
whenever you make a change to your source file.
If you're interesting in using Emacs, I'd say it's worth a shot. There's a bit of a learning curve, but it's not as steep as it looks up front :)
Also, I cannot recommend the Racket programming language(s) enough. There is an incredibly straightforward way to set it up for SICP, and it's a much more forgiving environment than Emacs. Let me know if you are interested and want any help getting started.