Hi I am trying to solution SICP 1.40
I am using DrRacket and I keep getting this error:
define: expected only one expression for the function body, but found 2 extra parts
on this area of the code
This is my full code:
(* 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))
Please let me know what are your thoughs. I am new to both tool and loanguage. Thank you!
You're using one of the teaching languages that come with Racket, it looks like this one has some restrictions: for example, you cannot have more than one expression inside a procedure definition.
This is easy to fix, just switch to a more powerful language. Click on the bottom-left corner of Racket's window, and select "Determine language from source". Edit your source file so it starts with a line specifying the language you want to use:
#lang racket
Now you'll have full access to all the language features, both for beginners and advanced users. Alternatively, you could use a language tailored for SICP, this is highly recommended:
#lang sicp