REBOL 3.0

Comments on: SWITCH as a native?

Carl Sassenrath, CTO
REBOL Technologies
21-May-2007 18:43 GMT

Article #0090
Main page || Index || Prior Article [0089] || Next Article [0091] || 11 Comments || Send feedback

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).

11 Comments

Comments:

Henrik
21-May-2007 15:41:02
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.
Brian Hawley
21-May-2007 17:05:55
The native switch in 2.7.5 seems to work well. Is it a mezzanine again in R3?
Paul
21-May-2007 17:33:36
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.
Carl Sassenrath
22-May-2007 12:14:54
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.
Scot
22-May-2007 14:24:44
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.
Maxim Olivier-Adlhoch
23-May-2007 9:06:40
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.

Pier Johnson
23-May-2007 21:49:05
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

][

when/choice/fallback [

red [ return say "stop" ] green [ return say "go" ] yellow [ return say "slow down" ]

][return say "lights broken, watch out"] ]

[see: http://www.rebol.net/cookbook/recipes/0052.html]

Oldes
24-May-2007 3:22:19
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."
    [throw]
    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]
    ]
]
Anton Rolls
3-Jun-2007 5:29
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.
Anton Rolls
3-Jun-2007 5:31:34
Oh yes, and I've been using it in View 2.7.5 since pretty soon after it was released, I guess.
Oldes
14-Nov-2010 5:46:33
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)]
2

Post a Comment:

You can post a comment here. Keep it on-topic.

Name:

Blog id:

R3-0090


Comment:


 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote
 
 

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

REBOL 3.0
Updated 10-Dec-2017 - Edit - Copyright REBOL Technologies - REBOL.net