In DrRacket there is a SICP compatibility language
In the documentation there is an easy guide to how it's installed from DrRacket:
Open the Package Manager: in DrRacket choose the menu "File" then choose "Package Manager...".
In the tab "Do What I Mean" find the text field and enter: "sicp"
Click the "Install" button. This produces lots of output. Don't worry about it even when there are warnings.
Test it. Make sure DrRacket has "Determine language from source" in the bottom left corner. Write the following program and click RUN:
#lang sicp
(inc 42)
; ==> 43
Here is a more advanced test that uses the picture language, which needs to be included with #%require
:
#lang sicp
(#%require sicp-pict)
;; paint-hires / paint-hi-res renamed to just paint
(paint (below (beside diagonal-shading
(rotate90 diagonal-shading))
(beside (rotate270 diagonal-shading)
(rotate180 diagonal-shading))))
Click RUN and you should see a square in the interactions window that gets brighter towards the center.
Alternatively, you can also do step 1-3 from a terminal/shell by running the following:
raco pkg install sicp
From here you do step 4. in the first installation instruction to test it.
raco pkg
didn't workIn DrRacket there is also an old version of SICP compatibility language. While having bottom left select box at "Determine language from source" You may just add:
#lang planet neil/sicp
as the only line in the definitions (top text area) and press RUN and it will be installed. Restart DrRacket and you'll find it available in the language drop down. Good luck.
You might get lots of error messages in red. Just ignore it and restart DrRacket. You might not find the choice in the language menu anymore, but by starting every file with #lang planet neil/sicp
it still works as a module language.
Judging from the errors, it seems to relate to the picture language module. I tested this sniplet and it still works:
(paint-hires (below (beside diagonal-shading
(rotate90 diagonal-shading))
(beside (rotate270 diagonal-shading)
(rotate180 diagonal-shading))))
Sylwester's answer was what I wanted. However, I have noticed that Racket 6.5 has added direct support for SICP. I think people may want to know that.
Now one can write code like the following in Racket after SICP support is added:
#lang sicp
(#%require sicp-pict)
(paint einstein)
[Nice start; keep going, you'll enjoy Scheme!]
In Scheme, programs are developed in an environment. The environment defines a mapping from identifiers to values. Some of the values are functions, some are numbers, etc. When you define a function:
(define (sqrt x)
(sqrt-iter 1.0 x))
the identifier x
is bound as an argument to sqrt
, the value 1.0 is a number, and the identifier sqrt-iter
is coming from the environment.
A question to ask yourself is "where is sqrt-iter
defined; what is it bound to?" Since it is not defined by you, sqrt-iter
must come from an environment built into your Scheme or imported into your Scheme. You've not imported anything and sqrt-iter
is not defined in Scheme (see resources for R5RS or others). Thus sqrt-iter
is unbound.
The same logic applies to every identifier including your use of word
.
In your implementation of word?
the syntactic-keyword let
is used to introduce new bound identifiers. When you write (number? number?)
you are introducing a new identifier number?
(on the left) and binding it to number?
(on the right) coming from the environment (it is defined in Scheme). Using let
for this isn't really buying you anything. Your code for word?
could be implemented as:
(define (word? x)
(or (symbol? x) (number? x) (string? x))) ;; number?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With