scheme - 我在计划中做错了什么?

标签 scheme

当我输入以下内容时:

(define (root a b c)
   (/ (+ (-b) (sqrt (- (exp b 2) (* 4 a c)))) (* 2 a)))

然后输入:

(root 3 6 2)

我收到一条消息,表明该过程有两个参数,但只需要一个。我做错了什么?

最佳答案

exp 函数实际上并不计算指数,它还执行其他数学操作。 (我不知道。)

您想要的通常称为“power”的 pow ,但可能在您的环境中没有定义,所以我建议您定义自己的 square 方法:

(define (square x) (* x x))

然后:

(define (root a b c)
   (/ (+ (- b) (sqrt (- (square b) (* 4 a c)))) (* 2 a)))

编辑:哦,您还必须更改几个间距问题,例如 (* 4 a c) 而不是 (*4 a c)(- b) 而不是 (-b)。您始终必须用空格将运算符与操作数分隔开。

关于scheme - 我在计划中做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3376633/

相关文章:

python - 帮我写我的 LISP :) LISP environments, Ruby Hashes

scheme - Lisp 程序(使用 Scheme 48 1.9 解释器)找出级数 1^3 + 2^3 + … 的总和。 + n^3

parsing - R5RS 方案中未加引号的向量

lisp - 在没有程序的方案语言中使用 "map"?

lisp - 在 Scheme 中创建斐波那契数列?

macros - Racket 阅读器宏

scheme - 何时在 Scheme 中使用 (values ...) (define-values ...)

clojure - Clojure 中 print 函数的方案等效项

scheme - 类似于 SICP 中的 "picture language"的小语言

syntax-error - 为什么返回错误 'Cannot read property ' car' of undefined [ ]' 即使我有空列表的回退?