Jose Jose - 5 months ago 26
Scala Question

if/else in Scala: Illegal start of simple expression/Il

These are the errors:

scala.scala:13: error: not found: value listaFibonaccisAux
listaFibonaccisAux int 0
scala.scala:4: error: illegal start of simple expression
if (int>fibby) fibby :: (listaFibonaccisAux int (n+1))
scala.scala:1: error: illegal start of definition
else List()
scala.scala:1: error: eof expected but '}' found.

And here's my code, the errors seem to refer to the simple
statements, I already tried wrapping and unwrapping stuff in parens, but it did not help:

def listaFibonaccis (int:Int):List[Int]=
listaFibonaccisAux (int, 0)

def listaFibonaccisAux (int:Int, n:Int):List[Int]=
var fibby = fib n
if (int> fibby)
fibby :: (listaFibonaccisAux (int, (n+1)))

def fib( n : Int) : Int = n match
case 0 | 1 => n
case _ => fib( n-1 ) + fib( n-2 )

finds a number
in the fibonacci sequence

creates a list of fibonacci numbers using fib, and stops when the numbers get bigger than int

is just a simple wrapper to call the other one with the 0 to start it

it's a plain
statement giving me trouble, and that's sad.

Answer Source

The compiler is complaining about the if/else because it doesn't think the line before has ended properly.

Try this: fib(n)

While "infix" (space notation) is sometimes handy...

instance.method(arg) into instance method arg can't be applied as you've tried to use it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download