Variable or constant? Constant patterns can have symbolic names. You saw this already when we used Nil as a pattern. Here is a related example, where a pattern match involves the constants E (2.71828…) and Pi (3.14159…):
scala> import math.{E, Pi} import math.{E, Pi} scala> E match { case Pi => “strange math? Pi = “+ Pi case _ => “OK” }
res11: java.lang.String = OK
As expected, E does not match Pi, so the “strange math” case is not used. How does the Scala compiler know that Pi is a constant imported from scala.math,andnotavariablethatstandsfortheselectorvalueitself? Scala uses a simple lexical rule for disambiguation: a simple name starting with a lowercase letter is taken to be a pattern variable; all other references are taken to be constants.