arrays - Error: Not found: Value S (Scala) -
val array(k,s) = readline.split(" ").map(_.toint)
this code works fine. not this:
val array(k,s) = readline.split(" ").map(_.toint)
capitalizing "s" here gives me error: error: not found: value s
what going on?
when creating k
, s
identifiers val array(k,s) = ...
, using pattern matching define them.
from scala specifications (1.1 identifiers):
the rules pattern matching further distinguish between variable identifiers, start lower case letter, , constant identifiers, not.
that is, when val array(k,s) = ...
, you're matching s
against constant. since have no s
defined, scala reports error: not found: value s
.
note scala throw matcherror
if constant defined still cannot find match :
scala> val s = 3 s: int = 3 scala> val array(k, s) = array(1, 3) k: int = 1 scala> val array(k, s) = array(1, 4) scala.matcherror: [i@813ab53 (of class [i) ... 33 elided
Comments
Post a Comment