简体   繁体   English

Racket是否支持内部“定义”?

[英]Does Racket support internal “define”?

I'm new to functional language and I'm doing SICP programming assignments using Racket. 我是功能语言的新手,我正在使用Racket进行SICP编程任务。

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 (yk) ): 下面是一段代码,并且Racket通知我define: expected only one expression for the function body, but found 5 extra parts在第5行中define: expected only one expression for the function body, but found 5 extra parts(define (yk) ):

(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? 有人知道如何正确配置Racket,或者不支持内部“定义”?

Indeed, it's as you say: internal define s are not supported by the Advanced language. 实际上,正如您所说:高级语言不支持内部define 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 . 对于使用SICP练习,我被告知最好使用neil/sicp包: 此处详细说明了使用它的说明

However, even the standard Racket language ( #lang racket ) will support internal define s without problems. 但是,即使是标准的Racket语言( #lang racket )也会毫无问题地支持内部define

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM