As a follow-up to this question
Here is some code that compiles and runs correctly, using captures.
val myString = "ACATCGTAGCTGCTAGCTG"
val nucCap = "([ACTG]+)".r
myString match {
case nucCap(myNuc) => println("dna:"+myNuc)
case _ => println("not dna")
}
>scala scalaTest.scala
dna:ACATCGTAGCTGCTAGCTG
Here is simpler code, without capture, that does not compile.
val myString = "ACATCGTAGCTGCTAGCTG"
val nuc = "[ACGT]+".r
myString match {
case nuc => println("dna")
case _ => println("not dna")
}
>scala scalaTest.scala
scalaTest.scala:7: error: unreachable code
Seems like the matching should return a boolean regardless of whether a capture is used. What is going on here?