首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >调用其中的函数[保持]时未定义的函数错误

调用其中的函数[保持]时未定义的函数错误
EN

Stack Overflow用户
提问于 2019-07-17 07:11:27
回答 1查看 0关注 0票数 0

尝试在自己中调用函数时,我收到一个未定义的函数错误。

我已经测试了两个猜测好吗?并且更好地猜测seperatley并且它们完美地工作。然后我调用(square_root 1 2)来尝试找到2的平方根。

;;;;program to find square root

(defun sqaure_root (guess x)
  (if (guess-okay? guess x)
      guess
    (square_root (better-guess guess x) x)))

(defun guess-okay? (guess x)
  "returns true if guess is within one 0.001 of value of square root"
  (> 0.001 (abs-x (- (square-x guess) x))))

(defun better-guess (guess x)
  "takes a guess and makes it a more accurate guess using newtons method of succsesive apporximations"
  (/ (+ guess (/ x guess)) 2))

错误是'undefined function square_root',我不明白因为我已经定义了它。我认为这个问题与调用函数中的函数有关,但我不确定。

EN

回答 1

Stack Overflow用户

发布于 2019-07-17 16:51:58

正如其他人所提到的,您的函数定义不正确。您的代码应如下所示:

;;;;program to find square root

(defun square_root (guess x)
  (if (guess-okay? guess x)
      guess
    (square_root (better-guess guess x) x)))

(defun guess-okay? (guess x)
  "returns true if guess is within one 0.001 of value of square root"
  (> 0.001 (abs-x (- (square-x guess) x))))

(defun better-guess (guess x)
  "takes a guess and makes it a more accurate guess using newtons method of succsesive apporximations"
  (/ (+ guess (/ x guess)) 2))

你在函数定义中拼错了“square”,这就是为什么“square_root”被认为是未定义的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100007076

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档