将mit-scheme与REPL和Editor一起使用 [英] Use mit-scheme with REPL and editor together
问题描述
我正在通过
此后,我运行 mit-scheme --edit
打开Edwin.我尝试使用 code.scm
文件中的代码,但无法识别.这是 code.scm
文件中的代码:
这就是我想要做的:注意,在此图片中,我可以键入命令,然后按Enter,它会自动运行命令.但是,我希望能够调用(fib 5)
,它引用了 code.scm
文件中的函数.
有人可以一步一步解释如何做到这一点吗?在查看计划网站的文档时会感到困惑.
MIT计划REPL中实际上有一个内置的 load
过程.评估
(加载"path/to/file.scm")
使位于 path/to/file.scm 的Scheme文件在顶层被评估(请注意,在文件名前后用双引号引起来).
而且,事实证明,可以使用同一功能重新加载文件.考虑到这一点,可能的工作流程"将被确定.可能看起来像这样:
- 创建新的源文件
- 评估REPL中的
(加载"path/to/file.scm")
- 编辑源文件
- 评估REPL中的
(加载"path/to/file.scm")
- ...等等.
不幸的是,我认为没有内置的重新加载"程序.但是...如果您发现自己进行了很多工作(如我想象的那样),则总是可以在黑客会议开始时迅速编写自己的文章:
(定义(重新加载)(加载"path/to/file.scm"))
然后只要对源文件进行更改,只需调用(重新加载)
.
如果您对使用Emacs感兴趣,那么值得一试.有一些学习曲线,但并不像前面看起来那么陡峭:)
此外,我不能充分推荐球拍编程语言.有一种非常直接的方法可以为SICP进行设置,并且它的环境比Emacs宽容得多.如果您有兴趣并希望获得任何帮助,请告诉我.
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.
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.
这篇关于将mit-scheme与REPL和Editor一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!