I keep getting this error when writing a simple recursive function in Scala. What am I missing?
scala> def count(n1:Int, n1:Int) : List[Int] = (n1 < n2) ? List() : List(n1, count((n1 - 1), n2))
<console>:1: error: ';' expected but '(' found.
def count(n1:Int, n1:Int) : List[Int] = (n1 < n2) ? List() : List(n1, count((n1 - 1), n2))
In Scala the ternary operator is
if. So,?and:can be replaced with the usualifandelsekeywords.Also, where is
n2defined? I’ll guess incountlike thisdef count(n1:Int, n2:Int) : List[Int] = ...