MATCH in Rust vs. SWITCH

We're on the cusp of practical "dialected function calls"

This means that predicates will be able to handle one of the biggest reasons for multiple switch cases: multiple datatypes.

switch/match value [
    integer! [
        ...
    ]
    [any-series? tag!] [
        ...
    ]
]

This might incentivize MATCH being willing to take a SPLICE!, so your cases could be clearer:

switch/match value [
    integer! [
        ...
    ]
    ~[any-series? tag!]~ [
        ...
    ]
]

Maybe even you'd want all your cases to be splices, to call them out better:

switch/match value [
    ~[integer!]~ [
        ...
    ]
    ~[any-series? tag!]~ [
        ...
    ]
]

(That might disincentivize being willing to take quasiform branches and turn them to antiforms, because you could use quasiforms to get safety by not being branches.)

If you're doing things like matching integers, I'd propose some kind of "FIND-in-SPLICE" function:

>> xxx 1 ~[1 2 3]~
== 1

>> xxx 4 ~[1 2 3]~
== \~null~\  ; antiform

>> xxx 1 1
== 1

>> xxx 1 4
== 1

So you could do things like:

switch/xxx 4 [
    ~[1 2 3]~ [...]
    4 [...]
 ]

Again: if you thought it was clearer to put all the cases in splices you could:

switch/xxx 4 [
    ~[1 2 3]~ [...]
    ~[4]~ [...]
 ]

Solve for the name of XXX.

This looks like a stellar direction for the core native, and would allow branches to be ANY-BRANCH?, so quoted values could be used.

Anything more interesting that you want, you can build.

1 Like