Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scala - error: not found: value

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?

like image 686
catch23 Avatar asked Aug 18 '13 14:08

catch23


1 Answers

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.

like image 117
Shadowlands Avatar answered Sep 20 '22 23:09

Shadowlands