liberal SWITCH eval, kill SWITCH/DEFAULT, CASE fallout #822
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The speculative feature of "SWITCH fallout" has been endorsed as a
legitimate way to return a value from a switch. This says that if the
last match item is reached with no associated branch block after it,
the match item itself is the evaluative result:
A question posed about this was:
The decision was that for Rebol's domain, this kind of implementation
choice goes well with the "fast-and-loose" character of the language,
especially with a "fully evaluative switch". It enables styles of
coding that may appeal to programmers who are already used to the
general flexibility of the language, such as:
Going along with the endorsement is the elimination of SWITCH/DEFAULT,
which is not relevant considering the null protocol. Cases that don't use
the result can get the same effect with:
But more importantly, if the result is to be used, you can use the fallout
feature...or it can work with ELSE or UNLESS or any of the other
null-triggered constructs.
Since SWITCH allows the last evaluated condition to fall out, this
extends the ability to CASE. CASE statements now have more structure,
expecting a condition/block alternation...though blocks may appear in
the conditions themselves. Fallout presents a more elegant and
matching way of handling no match. Historically this was done with
a truthy final condition:
For fail in particular, this would always have worked if written with
the fail in an unpaired condition slot:
But with fallout, any value can appear there:
One strong argument in favor of the feature is that people can use it
if they want, and ignore it if they want. But it's an option which
errs on the side of expressiveness over strict structure--and anyone
who wants more structure can build that into their own dialects.