如何在 DrScheme 中包含文件?
我正在使用 DrScheme 来完成 SICP,并且我注意到某些过程(例如,square
)被反复使用。 我想将它们放在一个单独的文件中,以便我可以将它们包含在其他程序中,而不必每次都重写它们,但我似乎不知道如何做到这一点。
我试过了:
(load filename)
(load (filename))
(load ~/path-to-directory/filename)
(require filename)
(require ~/path-to-directory/filename)
(require path-from-root/filename)
这些都不起作用。 显然我正在抓住救命稻草——非常感谢任何帮助。
I'm using DrScheme to work through SICP, and I've noticed that certain procedures (for example, square
) get used over and over. I'd like to put these in a separate file so that I can include them in other programs without having to rewrite them every time, but I can't seem to figure out how to do this.
I've tried:
(load filename)
(load (filename))
(load ~/path-to-directory/filename)
(require filename)
(require ~/path-to-directory/filename)
(require path-from-root/filename)
None of these works. Obviously I'm grasping at straws -- any help is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 MIT/GNU Scheme 中,您可以加载这样的文件:
但我不知道它在 DrScheme 中是否有效。
In MIT/GNU Scheme, you can load a file with something like this:
But I do not know if it works in DrScheme.
我相信您正在寻找:
(require) 表达式用于加载模块。
I believe you are looking for:
The (require) expression is for loading modules.
从您的问题中不清楚您正在使用什么语言级别; 某些遗留语言可能会使某些机制不可用。
最好的包含/抽象机制是模块的机制。
首先,将您的语言级别设置为“模块”。 然后,如果我将这两个文件放在同一目录中:
File uses-square.ss:
File square.ss :
然后我可以在“uses-square.ss”缓冲区上点击“run”,一切都会按照您的方式工作d 期望。
警告:未经测试的代码。
It's not clear from your question what language level you're using; certain legacy languages may make certain mechanisms unavailable.
The best inclusion/abstraction mechanism is that of modules.
First, set your language level to "module". Then, if I have these two files in the same directory:
File uses-square.ss:
File square.ss :
Then I can hit "run" on the "uses-square.ss" buffer and everything will work the way you'd expect.
Caveat: untested code.