CGA Grammar: case/else

975
2
03-05-2012 06:09 PM
Status: Open
AndréCardoso
New Contributor III
Would be nice to allow statements outside the case/else construct.

For example, this is NOT allowed (to my knowledge):
Lot -->
    set(material.name, "diffuse")
    case attrHello == 1:
         Building
    else:
         Garden

while this IS valid:
Lot -->
    case attrHello == 1:
         set(material.name, "diffuse")
         Building
    else:
         set(material.name, "diffuse")
         Garden

This is a very simple (dummy) example. However, for complex things, this restriction becomes very annoying, and turns your code very verbose and unclean.
You could put the common code in a intermediate rule but, again, you're writing code which is becoming unreadable

Thanks,
André
2 Comments
chandesrisbasile1
better: http://www.scala-lang.org/node/120

object MatchTest1 extends Application {
  def matchTest(x: Int): String = x match {
    case 1 =>"one"case 2 =>"two"case _ =>"many"
  }
  println(matchTest(3))
}
chandesrisbasile1
a better syntax: http://www.scala-lang.org/node/120

object MatchTest1 extends Application {
  def matchTest(x: Int): String = x match {
    case 1 =>"one"case 2 =>"two"case _ =>"many"
  }
  println(matchTest(3))
}