Comments on: SWITCH as a native?
I would be interested in hearing your feedback on the idea of making switch into a native, or any other improvements that we may want to make to it. (Yes, it is native in 2.7 beta, but I think only a few developers have tried it, and I have very little feedback from users on this change. In R3, it is not yet a native -- but should it be?)
The switch function is used quite frequently in programs, but it presents challenges to new users, due to it's non-evaluated case labels.
Let me know what you think. I'll leave the function as-is unless a good case is made for changes (no pun intended).
I can only say that I use SWITCH in loops a lot, so performance is important there, but I have no idea on the impact on a native vs. mezzanine SWITCH.|
The native switch in 2.7.5 seems to work well. Is it a mezzanine again in R3?|
I agree that the native switch in 2.7.5 was well thought out and remember we debated it heavy on Altme. I'm all for keeping it native for speed reasons. It is my hope that we could at some point at least have code that is native but its function publicly disclosed in some cases so we can understand how some natives operate. That way we can source some native functions but not be able to change their function. I'm not sure if something that goes native still retains a REBOL footprint or if native means something is then C'ish.|
Sometimes it seems like I go in circles. Yes, 2.7 has switch native, but probably very few users have tried it. So, do you want to keep it that way? Currently, in R3, it is not yet native, but that can change.|
I like and use switch quite a bit so the faster the better for me. Don't know if mezz versus native makes much difference.|
Don't think no news is bad news... in this case, its quite the opposite :-)
I wonder why you say little of us have tried it... Pretty much everyone is using 2.7 now no? I think I must have a few hundred calls to switch in my code, and the fact that 2.7 didn't trip any one of them is proof that its pretty backwards possible in actual code...
Knowing that switch is native and much faster means I am relying on it more than before. the new /all refinement is also very handy on some algorythms, especially when dealing with multiple possible input datatypes, I can easily convert and trickle the type into other types, but still rely on the fast switching. :-)
and I think switch being the most used vector jumping pattern in rebol (as opposed to case or select), it should definitely stay native. IIRC the latest version of mezz based switch with /all refinement was starting to be quite large, and slowish...
In any case, if someone wants to adapt it ... he can still redefine it as a mezz of his own.
I use a tweaked version of a brilliant gem case control (thanks Marco) over any other construct in my code.
It beats the pants off of if [ ] and either  .
My code looks like this :
light: func [
/choice -- variant jumps to choice
/fallback -- provides default code
/red /green /yellow
red [ return say "stop" ]
green [ return say "go" ]
yellow [ return say "slow down" ]
][return say "lights broken, watch out"]
Maxim is right. I'm using always the latest alfa and beta releases and you may be sure that if I would found a bug I can shout:-) Keep it native. And if there is someone who wants to use old mezzanine version, he can use:
switch: func [
"Selects a choice and evaluates what follows it."
value "Value to search for."
cases [block!] "Block of cases to search."
/default case "Default case if no others are found."
either value: select cases value [do value] [
either default [do case] [none]
I'm quite happy with the new SWITCH, native in 2.7.x
Being native, I know it's fast.
I agree it's nice to have the equivalent rebol mezz code hanging around.
In Rebol 3, it's good to keep SWITCH as mezzanine for a while, so we have a chance to debug it - when some other part of Rebol 3 affects it, we can reproduce and isolate.|
Oh yes, and I've been using it in View 2.7.5 since pretty soon after it was released, I guess.|
I've just found that the new native SWITCH, as well as the old mezzanine does not have /CASE refinement.
So I use in my code PARSE/CASE instead:
>> parse/case "A" ["a" (print 1) | "A" (print 2)]
Post a Comment:
You can post a comment here. Keep it on-topic.