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:
- I installed mit-scheme with
brew install mit-scheme
- I have a local file named
code.scm
- In terminal, I load the file with
mit-scheme --load /Users/name/Desktop/code.scm
- Terminal now starts the REPL and everything works. The problem is that if I add new code to the file
code.scm
, I have to quit terminal and call this again:mit-scheme --load /Users/name/Desktop/code.scm
System details:
- macOS Catalina - 10.15.6
- Default Mac Terminal app - Version 2.10
- MIT/GNU Scheme running under OS X
- The text editor I use is Atom - 1.50.0
Question Edit #1 (Based on answer below)
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 thecode.scm
file but it doesn't recognize it. This is the code incode.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. Evaluatingcauses 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:
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.