问题描述
我正在通过SICP工作.目前,在第一章中,让Racket重新定义基本体"时遇到了问题.例如,我的印象是我应该能够任意执行(define + 5)
,这很好,或者重新定义了sqrt
过程.相反,我得到了:
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: +
我目前将语言设置为R5RS,在我看来,该语言将解决与SICP的兼容性问题.
I have the language currently set to R5RS, which I was under the impression would take care of the compatibility issues with SICP.
推荐答案
即使在可能的情况下,在没有真正了解系统如何对此做出响应的情况下,也不应执行此类重新定义.例如,如果您重新定义+
,是否还会有其他代码中断?在Racket的情况下,答案是否"-但这是因为您并没有真正重新定义+
:而是定义了一个 new +
,该代码只包含您的代码可以使用.
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.
关于语言选择-球拍R5RS模式是一种非常严格的模式,它不是您通常想要使用的模式.要获得更适合SICP的 环境,请参见Neil Van Dyke的 SICP支持页面,它将为您提供专门针对该书的语言. (IIRC,甚至还具有书籍展示的图形语言.)
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.)
这篇关于Racket博士对SICP的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!