SICP 练习 1.40 问题

SICP Exercise 1.40 Issue

您好,我正在尝试解决 SICP 1.40

我正在使用 DrRacket,但我一直收到此错误:

define: expected only one expression for the function body, but found 2 extra parts

在代码的这个区域

这是我的完整代码:

  (* x x))

(define (cube x) (* x x x))

(define (cubic a b c)
  (lambda (x)
    (+ (cube x)
       (* a (square x))
       (* b x) c)))

; Newton's methods pages 97 to 102
(define (deriv g)
    (lambda (x) (/ (- (g (+ x dx)) (g x)) dx)))
(define dx 0.00001)
(define tolerance 0.00001)
(define (fixed-point f first-guess)
    (define (close-enough? v1 v2)
        (< (abs (- v1 v2)) tolerance))
    (define (try guess)
        (let ((next (f guess)))
            (if (close-enough? guess next)
                next
                (try next))))
    (try first-guess))
(define (newton-transform g)
    (lambda (x) (- x (/ (g x) ((deriv g) x)))))

(define (newtons-method g guess) (fixed-point (newton-transform g) guess))

请告诉我你的想法。我对工具和语言都很陌生。谢谢!

您正在使用 Racket 附带的一种教学语言,看起来这个语言有一些限制:例如,您不能在一个过程定义中有多个表达式。

这很容易修复,只需切换到更强大的语言即可。单击 Racket 的 window 左下角,然后 select “从源中确定语言”。编辑您的源文件,使其以指定您要使用的语言的行开头:

#lang racket

现在您可以完全访问所有语言功能,无论是初学者还是高级用户。或者,您可以使用为 SICP 量身定制的语言,强烈推荐:

#lang sicp