Reputation: 2259
I'm new to functional language and I'm doing SICP programming assignments using Racket.
Below is a snippet of code, and Racket informs me that define: expected only one expression for the function body, but found 5 extra parts
, in line 5 ((define (y k)
):
(define (simpson f a b n)
(define h (/ (- b a) n))
(define (y k)
(f (+ a (* k h))))
(define (factor k)
(cond ((or (= k 0) (= k n))
1)
((odd? k)
4)
(else
2)))
(define (term k)
(* (factor k)
(y k)))
(define (next k)
(+ k 1))
(if (not (even? n))
(error "n can't be odd")
(* (/ h 3)
(sum term (exact->inexact a) next n))))
I guess this problem is related to the language settings, but I already use "advanced" option.
Anybody know how to configure Racket properly, or internal "define" is not supported?
Upvotes: 3
Views: 1374
Reputation: 223093
Indeed, it's as you say: internal define
s are not supported by the Advanced language. For working with the SICP exercises, I've been told it's best to use the neil/sicp
package: instructions for using this are detailed here.
However, even the standard Racket language (#lang racket
) will support internal define
s without problems.
Upvotes: 7