32

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.

afkbowflexin
  • 4,029
  • 2
  • 37
  • 61
  • This (define + 5) actually works on my machine (Ubuntu 12.04) with DrRacket 5.1.3 now. Did they change the default? – dividebyzero Jun 10 '12 at 10:44

3 Answers3

34

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.)

DjebbZ
  • 1,594
  • 1
  • 18
  • 34
Eli Barzilay
  • 29,301
  • 3
  • 67
  • 110
  • I actually ended up going ahead and installing Neil Van Dyke's package, so that I could have support for the picture language and for streams. Initially, I was just irritated that I couldn't work through some of the examples in the book. Thanks! – afkbowflexin Aug 30 '10 at 21:28
20

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!

jpswain
  • 14,642
  • 8
  • 58
  • 63
  • 1
    Hi, in my office the site http://http://planet.racket-lang.org is blocked so i cannot download the SICP support module through DrRacket. Is there any way i can directly download the files and then manually install the files to DrRacket? Thanks. – weima Jul 09 '12 at 08:59
11

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

afkbowflexin
  • 4,029
  • 2
  • 37
  • 61