In this part I show and explain the switch expression, which is defined in Xbase, so you can also have that in you Xtext DSL if you want :-)
In the tutorial at EclipseCon on Thursday we will show how to embed Xbase expressions in a simple DSL.
Here again I use Xtend for the demo:
Looks cool :)
ReplyDeleteSo, the output of
val l = newArrayList(true, false)
for (s: l) {
switch(s) {
case s == false: println(s);
}
}
is "false" and not empty?
Yes, but we will likely add a compile error if you switch over boolean because it doesn't make sense and to avoid this kind of confusion.
ReplyDeleteGenerally spoken: If the guard is of type boolean, the value in the switch is ignored.
You could have written:
val l = newArrayList(true, false)
for (s: l) {
switch('foo') {
case s == false: println(s);
}
}
and it would have the same effect.
An error or a warning could be a life-saver IMHO. Looking forward to the upcomming episodes :)
ReplyDeleteI'm really looking forward to seeing a small generator example. So far this looks like "Java - How it should be" =)
ReplyDelete