Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dr Racket problems with 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.

like image 341
afkbowflexin Avatar asked Aug 30 '10 03:08

afkbowflexin


3 Answers

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

like image 106
Eli Barzilay Avatar answered Nov 14 '22 22:11

Eli Barzilay


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!

like image 21
jpswain Avatar answered Nov 14 '22 23:11

jpswain


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

like image 11
afkbowflexin Avatar answered Nov 14 '22 22:11

afkbowflexin