Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
519 views
in Technique[技术] by (71.8m points)

scheme - Which lang packet is proper for SICP in Dr.Racket?

I'm trying with SICP and I got some code. So I started with:

#lang scheme
(word 'comp 'uter)

Returned error: Function (word) undefined.

Even if I tried to copy this into IDE(Run):

(define word?
  (let ((number? number?)
        (symbol? symbol?)
        (string? string?))
    (lambda (x)
      (or (symbol? x) (number? x) (string? x)))))

Still the same.

I think it may be certain problem with version of language or else.


Above are from "Simply Scheme" and when I introduce code exactly in SICP:

(define (sqrt x)
    (sqrt-iter 1.0 x))

IDE returned sqrt-iter undefined. The code can be found in chapter one: http://mitpress.mit.edu/sicp/code/index.html

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In DrRacket there is a SICP compatibility language

1. From the Package Manager

In the documentation there is an easy guide to how it's installed from DrRacket:

  1. Open the Package Manager: in DrRacket choose the menu "File" then choose "Package Manager...".

  2. In the tab "Do What I Mean" find the text field and enter: "sicp"

  3. Click the "Install" button. This produces lots of output. Don't worry about it even when there are warnings.

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

2 Command line installation

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.

3. Older versions or DrRacket using planet if the raco pkg didn't work

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...