Tôi vừa mới ở scala và đã cố gắng để vượt qua một số bảng tính scala dễ dàng.scala - lỗi: không tìm thấy: giá trị
IDE là phiên bản cộng đồng Intellij IDEA và hệ điều hành Ubuntu 12.04, sbt
được cài đặt chính xác.
Nhưng nó throws lỗi - error: not found: value
OI không thể hiểu tại sao điều này xảy ra:
Code:
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)
}
Output từ phía bên phải của màn hình:
> 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)
Bất kỳ đề xuất nào?
Cảm ơn, chỉ là những gì tôi cần. Ở phía bên kia, tôi thích chỉ nhập những gì chương trình cần, để rõ ràng, vì vậy tôi khuyên bạn nên sử dụng "import math.abs". –