Dr Racket 与 SICP 的问题

发布于 2024-09-17 08:21:26 字数 269 浏览 5 评论 0原文

我正在通过 SICP 进行工作。目前,在第一章中,我在让 Racket 重新定义“基元”时遇到问题。例如,我的印象是我应该能够任意执行 (define + 5) ,这样就可以了,或者重新定义 sqrt 过程。相反,我得到的是:

define-values: cannot change constant variable: +

我当前将语言设置为 R5RS,我的印象是它会解决与 SICP 的兼容性问题。

I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket to let me redefine "primitives". For instance, I was under the impression that I should be able to arbitrarily do (define + 5) and that would be fine, or redefine the sqrt procedure. Instead, I get this:

define-values: cannot change constant variable: +

I have the language currently set to R5RS, which I was under the impression would take care of the compatibility issues with SICP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

折戟 2024-09-24 08:21:26

即使可能,在没有真正了解系统对此有何反应的情况下,您也不应该进行此类重新定义。例如,如果重新定义+,其他代码会中断吗?在 Racket 的例子中,答案是“否”——但这是因为您实际上并没有重新定义 +:相反,您定义了一个新的 +,只有您的代码可以使用。

至于语言选择——Rackets R5RS模式是一个非常严格的模式,你通常不会想使用它。要获得对 SICP 更加友好的环境,请参阅 Neil Van Dyke 的 SICP 支持页面< /a> 将为您提供专门为本书制作的语言。 (IIRC,它甚至具有书籍展示的图形语言。)

Even if possible, such redefinitions are not something that you should do without really understanding how the system will react to this. For example, if you redefine +, will any other code break? The answer to that in Racket's case is "no" -- but this is because you don't really get to redefine +: instead, you define a new +, which only your code can use.

As for the language choice -- Rackets R5RS mode is a very strict one, and it's not something that you'd usually want to use. For a much more SICP-friendly environment, see Neil Van Dyke's SICP Support page which will provide you with a language specifically made for the book. (IIRC, it even has the graphical language that the books shows off.)

巷雨优美回忆 2024-09-24 08:21:26

我在尝试使用此处的 RSA 示例时遇到了问题(SICP 内容的一部分):
http://mitpress.mit.edu/sicp/psets/ps3/readme.html

为了让这个工作,我必须这样做:

1)通过将其添加到空白文件的顶部来运行初始下载:

#lang planet neil/sicp

然后点击“运行”

2)享受 DrRacket 非常用户友好的自动下载和安装PLAneT Neil 模块,去喝杯咖啡;-)

3) 安装完成后,关闭 DrRacket。

4) 重新打开,然后从选择语言列表中选择 SICP PLAneT 1.15。
(除了执行初始下载之外,我无法在顶部添加声明来为我工作。)

祝你好运!

I ran into problems trying to work thru the RSA example here (part of the SICP stuff):
http://mitpress.mit.edu/sicp/psets/ps3/readme.html

To get this working I had to do this:

1) Run thru the initial download by adding this to the top of a blank file:

#lang planet neil/sicp

and then hitting "Run"

2) Enjoy DrRacket's very user friendly, automatic download and install the PLaneT Neil module by going to grab a coffee ;-)

3) And then once it is installed, close DrRacket.

4) Reopen, and choose SICP PLaneT 1.15 from the Choose A Language list.
(I could not get adding the declaration at the top to work for me aside from doing that to perform the initial download.)

Good luck!

苍白女子 2024-09-24 08:21:26

在语言面板中,您需要禁用“不允许重新定义初始绑定”。这解决了这个问题。

In the language panel, you need to disable "disallow redefinition of initial bindings." This fixes the issue.

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