--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
I also agree. Having a match and switch also helps when updating large codebases.
--
Actually I didn't think about introducing a new keyword... but rather about just allowing non-constant cases.I'm probably missing something, but I don't really see how this could interfere with the new features...What if the compiler just "converted" non constant value to "case _ if( a == b ):" under the hood ?
On Sat, Apr 20, 2013 at 1:52 PM, Simon Krajewski <si...@haxe.org> wrote:
Am 20.04.2013 12:47, schrieb clemos:It's useful for this:
Maybe it would make sense to just consider making such cases (when using variables defined in scope) work just like before (or convert to "case _ if( x == a )") ?
Also I'm not sure I see how "match anything, put the of value of x into 'a'" is useful in such situations as you can simply use "x" in "default" or in "case _", can't you ?
switch(someCalculation()) {
...
case result:
}
Ok, why not :)Isn't it possible to "switch( var result = someCalculation() ){ default: trace(result); } ?Or introduce "switch( someCalculation() ){ default result : ... }" ?
But then, once again, I thought we could introduce a difference between existing identifiers in one hand ("normal" variable cases), and non-existing identifiers , like "result" in your example.Or use $result or such convention to have a clear distinction between capturing patterns and actual variables / values.
Also I didn't have the time to test, but Juraj seemed to say that the inline static variables are considered constant values, which IMHO brings even more confusion and unexpected behaviours:public var b = "foo";public inline var a = "bar";...switch( x ){case a : // a exists as inline static = considered a constantcase b : // b not being inline, this matches all other values ...}
As for what Mike said about AS3/JS vs C, I believe Haxe has always tried to follow ECMAScript.I'm not an expert, but I believe this breaks it pretty completely rather than "extending" it with additional features.
Also I don't really like the metadata solution.To me the point is more to polish the new feature that to support two different constructs.
Am 20.04.2013 18:39, schrieb clemos:
I prefer to follow the ML-style here instead of introducing some weird syntax for specific cases. After all, "case a" just a particular case of variable capture.
On Sat, Apr 20, 2013 at 1:52 PM, Simon Krajewski <si...@haxe.org> wrote:
Am 20.04.2013 12:47, schrieb clemos:It's useful for this:
Maybe it would make sense to just consider making such cases (when using variables defined in scope) work just like before (or convert to "case _ if( x == a )") ?
Also I'm not sure I see how "match anything, put the of value of x into 'a'" is useful in such situations as you can simply use "x" in "default" or in "case _", can't you ?
switch(someCalculation()) {
...
case result:
}
Ok, why not :)Isn't it possible to "switch( var result = someCalculation() ){ default: trace(result); } ?Or introduce "switch( someCalculation() ){ default result : ... }" ?
How is this confusing? It's consistent with usual inline variable behavior.But then, once again, I thought we could introduce a difference between existing identifiers in one hand ("normal" variable cases), and non-existing identifiers , like "result" in your example.Or use $result or such convention to have a clear distinction between capturing patterns and actual variables / values.
Also I didn't have the time to test, but Juraj seemed to say that the inline static variables are considered constant values, which IMHO brings even more confusion and unexpected behaviours:public var b = "foo";public inline var a = "bar";...switch( x ){case a : // a exists as inline static = considered a constantcase b : // b not being inline, this matches all other values ...}
It's pointless to discuss this, we will not introduce a new keyword this late in the release cycle. I'm sorry if it breaks parts of your code, but we conciously made the decision to enforce constant patterns. It's a fair limitation with simple workarounds, and having pattern matching is surely worth it.
As for what Mike said about AS3/JS vs C, I believe Haxe has always tried to follow ECMAScript.I'm not an expert, but I believe this breaks it pretty completely rather than "extending" it with additional features.
Also I don't really like the metadata solution.To me the point is more to polish the new feature that to support two different constructs.
Simon
--
I think the current pattern matching behavior of switch is good, and it requires only minor changes to existing code.
And for new user adoption, I do think it is important, which attracting more ML-style hard-core programers isn't a bad thing.
ClassicSwitch.hx - a macro which takes a switch statement and turns it into an if/elseif/else chain. This is useful if you want traditional ecmascript "switch" behaviour, not the kick-ass haxe pattern matching. Times this is useful: if one of your cases is a variable:
option1 = "Something1"; option2 = "Something2"; switch (someVar) { case option1: trace ("do something 1"); case option2: trace ("do something 2"); }
This doesn't work with pattern matching, because
option1
,option2
are seen as capture variables. With this macro, you could do:option1 = "Something1"; option2 = "Something2"; ClassicSwitch.from(switch (someVar) { case option1: trace ("do something 1"); case option2: trace ("do something 2"); });
... and things will behave as expected.
Some quick tests in the Main.hx below. Run with
haxe -x Main.hx
, in Haxe 3RC or above.
--
Right now, there is no pretty way to support both Haxe 2 and Haxe 3 switches via conditional compilation for a particular usage instance.Hi,I've recently updated all the Haxe PureMVC libraries to support both Haxe 2 & 3 to help smooth the transition towards the imminent Haxe 3 release.
While I'm also very thankful for all the fantastic updates, adding expressiveness and power to the language, I would also like to guard against alienating the ECMA-school potentials.
This lead me to fall back to IF statements for the PureMVC libraries, as was discussed with Cliff Hall here:
https://github.com/PureMVC/puremvc-haxe-util-pipes/pull/1#issuecomment-16710522
So, right now, if we keep with the switch statement,
switch ( message.getType() )
{
case Message.NORMAL:
case FilterControlMessage.SET_PARAMS:
would need to change to:
switch ( message.getType() )
{
case x if(x == Message.NORMAL):
case x if(x == FilterControlMessage.SET_PARAMS):
"
"
So, right now, if we keep with the switch statement,
switch ( message.getType() )
{
case Message.NORMAL:
case FilterControlMessage.SET_PARAMS:would need to change to:
switch ( message.getType() )
The former version should still work if NORMAL and SET_PARAMS are static inline variables.
{
case x if(x == Message.NORMAL):
case x if(x == FilterControlMessage.SET_PARAMS):
"
--
--
Please file an issue, it could be related to MESSAGE having a value of BASE + 'normal/'.