gpt4 book ai didi

scala - scala-错误: not found: value

转载 作者:行者123 更新时间:2023-12-03 13:29:29 26 4
gpt4 key购买 nike

我刚在Scala工作,并试图通过一些简单的Scala工作表。

IDE是Intellij IDEA社区版本,并且操作系统Ubuntu 12.04已正确安装sbt

但这会引发错误-error: not found: value
OI无法理解为什么会这样:

代码:

object session {
1 + 2
def abs(x: Double) = if (x < 0) -x else x <== update this line
def sqrtIter(guess: Double, x: Double): Double =
if (isGoodEnough(guess, x)) guess
else sqrtIter(improve(guess, x), x)

def isGoodEnough(guess: Double, x: Double) =
abs(guess * guess - x) < 0.001

def improve(guess: Double, x: Double) =
(guess + x / guess) / 2
def sqrt(x: Double) = sqrtIter(1.0, x)
sqrt(2)
sqrt(4)
}

从屏幕右侧输出:
> res0: Int = 3

> <console>:8: error: not found: value isGoodEnough
if (isGoodEnough(guess, x)) guess else sqrtIter(improve(guess, x), x)
^
<console>:8: error: not found: value improve
if (isGoodEnough(guess, x)) guess else sqrtIter(improve(guess, x), x)
^
> <console>:8: error: not found: value abs
abs(guess * guess - x) < 0.001
^
> improve: (guess: Double, x: Double)Double

> <console>:7: error: not found: value sqrtIter
def sqrt(x: Double) = sqrtIter(1.0, x)
^
> <console>:8: error: not found: value sqrt
sqrt(2)
^

> <console>:8: error: not found: value sqrt
sqrt(4)

有什么建议?

最佳答案

完整的错误消息是error: not found: value abs。找不到值“abs”。您需要math.abs。或者,您可以在需要这些数学函数之前在某处添加import math._

关于scala - scala-错误: not found: value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18299980/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com