I newly at scala and tried to pass some easy scala worksheet.
IDE is Intellij IDEA community edition and OS Ubuntu 12.04, sbt
was installed correctly.
But it throws error - error: not found: value
OI can't understand why this happen:
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 from right side of screen:
> 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)
Any suggestions?
The complete error message is error: not found: value abs
. The value "abs" wan't found. You want math.abs
. Alternatively you could add import math._
somewhere before you need these math functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With