问题
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:
Run
mit-scheme < /Users/Desktop/code.scm
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.
回答1:
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:
- Create new source file
- Evaluate
(load "path/to/file.scm")
in the REPL - Edit source file
- Evaluate
(load "path/to/file.scm")
in the REPL - ...etc.
Unfortunately, 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.
回答2:
You should use emacs with xscheme.el. It works much better.
If you continue as you do, you can also do mit-scheme < code.scm
or mit-scheme --edit code.scm
and you will also get a *repl* buffer inside edwin.
I recommend you the emacs way, however.
回答3:
A (load "/path/to/file")
command should be available to you within MIT Scheme and the Edwin editor it comes with. However, I would actually recommend that you use Emacs, and use Geiser within that to access both the REPL and to help with scheme file editing. It also makes dealing with various Scheme REPLs such as Chez Scheme, Racket, MIT Scheme, Guile, Chicken, Gambit and Chibi Scheme fairly effortless. The same (load "/path/to/file")
command would then be available to you within the REPL running under Geiser, within Emacs, but is generally much more powerful and seamless than when using the "naked" REPL. Emacs is very well tuned to use with Scheme and LISP. Highly recommended.
回答4:
Evaluate entire buffer: press M-o (M is Alt on Windows). When in source file window, press it. It will evaluate the entire buffer i.e. (re)load the entire source file (without even saving it first). I found it by googling "mit scheme edwin tutorial". Edwin is kind of Emacs itself.
This page says: "C-c C-s when done in a scheme-mode buffer [i.e. Scheme source file window], will switch to the Scheme interaction buffer [i.e. REPL]". i.e. you press C-x C-s to save file, M-o to evaluate (i.e. load), C-c C-s to switch to the REPL.
If you've split your screen with C-x 2
between a source file buffer and the REPL ("interactions buffer"), you can switch between them by pressing C-x o
(for "go to the other window").
来源:https://stackoverflow.com/questions/64328659/use-mit-scheme-with-repl-and-editor-together