如何在 DrScheme 中包含文件?

发布于 2024-07-29 21:39:32 字数 379 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

墨离汐 2024-08-05 21:39:34
(require "~/path-to-directory/filename")
(require "~/path-to-directory/filename")
故人如初 2024-08-05 21:39:34

在 MIT/GNU Scheme 中,您可以加载这样的文件:

(load "c:\\sample-directory\\sample-file.scm")

但我不知道它在 DrScheme 中是否有效。

In MIT/GNU Scheme, you can load a file with something like this:

(load "c:\\sample-directory\\sample-file.scm")

But I do not know if it works in DrScheme.

心凉怎暖 2024-08-05 21:39:33

我相信您正在寻找:

(include "relative/path/to/scheme/file.scm")

(require) 表达式用于加载模块。

I believe you are looking for:

(include "relative/path/to/scheme/file.scm")

The (require) expression is for loading modules.

不喜欢何必死缠烂打 2024-08-05 21:39:33

从您的问题中不清楚您正在使用什么语言级别; 某些遗留语言可能会使某些机制不可用。

最好的包含/抽象机制是模块的机制。

首先,将您的语言级别设置为“模块”。 然后,如果我将这两个文件放在同一目录中:

File uses-square.ss:

#lang scheme

(require "square.ss")

(define (super-duper x) (square (square x)))

File square.ss :

#lang scheme

(provide square)

(define (square x) (* x x))

然后我可以在“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:

#lang scheme

(require "square.ss")

(define (super-duper x) (square (square x)))

File square.ss :

#lang scheme

(provide square)

(define (square x) (* x x))

Then I can hit "run" on the "uses-square.ss" buffer and everything will work the way you'd expect.

Caveat: untested code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文