Dr.Racket 中哪个 lang 数据包适合 SICP? [英] Which lang packet is proper for SICP in Dr.Racket?

查看:60
本文介绍了Dr.Racket 中哪个 lang 数据包适合 SICP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SICP,我得到了一些代码.所以我开始:

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

#lang scheme
(word 'comp 'uter)

返回错误:函数(字)未定义.

Returned error: Function (word) undefined.

即使我试图将其复制到 IDE(运行)中:

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

还是一样.

我认为可能是语言版本或其他方面的某些问题.

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

以上来自Simply Scheme",当我在 SICP 中准确引入代码时:

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

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

IDE 返回 sqrt-iter 未定义.代码见第一章:http://mitpress.mit.edu/sicp/code/index.html

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

推荐答案

DrRacket 中有一个SICP 兼容语言

文档中有一个关于如何从 DrRacket 安装的简单指南:

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

  1. 打开包管理器:在 DrRacket 中选择菜单文件";然后选择包管理器...".

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

在按我的意思做"选项卡中找到文本字段并输入:sicp"

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.

测试一下.确保 DrRacket 具有从源代码确定语言";在左下角.编写以下程序并点击RUN:

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

这里有一个使用图片语言的更高级的测试,需要在#%require中包含:

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

点击 RUN,您应该会在交互窗口中看到一个方块,该方块越靠近中心越亮.

Click RUN and you should see a square in the interactions window that gets brighter towards the center.

或者,您也可以通过运行以下命令从终端/shell 执行步骤 1-3:

Alternatively, you can also do step 1-3 from a terminal/shell by running the following:

raco pkg install sicp

从这里开始执行第 4. 步安装说明中的测试.

From here you do step 4. in the first installation instruction to test it.

在 DrRacket 中还有一个 旧版本的 SICP 兼容语言.在从源中确定语言"处有左下角的选择框时您可以添加:

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

作为定义中的唯一一行(顶部文本区域)并按 RUN 它将被安装.重新启动 DrRacket,您会在语言下拉菜单中找到它.祝你好运.您可能会收到大量红色错误消息.只需忽略它并重新启动 DrRacket.您可能再也找不到语言菜单中的选项,但是通过以 #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.

从错误来看,似乎与图片语言模块有关.我测试了这个 sniplet,它仍然有效:

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

这篇关于Dr.Racket 中哪个 lang 数据包适合 SICP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆