I've mentioned before that AUGMENT can be used to implement the legacy SWITCH/DEFAULT behavior.
But looking at what seems like the "correct" formulation of that code today, we get:
switch-d: enclose (augment :switch [
/default "Default case if no others are found"
[block!]
]) lambda [f [frame!]] [
let def: f.default
eval f else (maybe def)
]
It points out the existence of void branches... so not branches that evaluate to void (e.g. [void]
) but code that evaluates to a branch to run, and that branch is void.
Considering this specific usage only, it suggests a semantic for ELSE of a VOID branch, which is that you want it to act like there was no branch at all. e.g. as if you'd written just eval f
with no ELSE.
>> if false [1 + 2]
== ~void~ ; anti
>> if false [1 + 2] else [10 + 20]
== 30
>> if false [1 + 2] else (void)
== ~void~ ; anti
Would the same apply to THEN?
>> if true [1 + 2]
== 3
>> if true [1 + 2] then [10 + 20]
== 30
>> if true [1 + 2] then (void)
== 3
I don't know if it's great, but it's certainly better than evaluating to NULL (via some void-in-null-out rationale) because that would trigger an ELSE branch.
>> if true [1 + 2] then (void) else [print "we don't want this."]
we don't want this.
But what should other branching constructs do, like CASE or SWITCH? Might a void branch suggest "opting out" of that particular branch?
case [
1 < 2 (void)
3 < 4 [print "Should this run?"]
]
A CASE (at least CASE/ALL) is supposed to be synonymous with a series of IF statements. And IF can't exactly do that, unless it decided to be NIHIL...
>> 1 + 2 if false (void)
== 3
That would be a bit weird, but, it does sort of parallel what happens when ELSE and THEN effectively vaporize themselves.
As with most things on the edge of usefulness, I don't know about this... other than the situation of wanting to revoke the ELSE branch in SWITCH-D. I'll keep an eye on it.