Soni They/Them L. <fakedme@gmail.com> wrote:
switch x do
case math.random() do print "a" end
case math.random() do print "b" end
case math.random() do print "c" end
else do print "e" end
end
-- desugars into
if x == math.random() then print "a"
elseif x == math.random() then print "b"
elseif x == math.random() then print "c"
else print "e" end
Okay, so we are taking about the same thing... though I still don't
necessarily see a practical use for this specific example.
With the current version of my switch/case patch providing a fallback to
using if/else for a switch construct with non-constant blocks isn't possible.
However, using my Token Storage system I could easily defer the non constant
case blocks... though the issue with fallthrough would still exist using
if/else constructs for non-constant values, which is the usual problem when
'desugaring' switch/case blocks that use fallthrough.
I suppose one fix to the issue would be to simply disallow fallthrough and
force a break for switch constructs that have non-constant case values.
Hmm, thanks for bringing this idea up, Soni. What you request may actually
be possible... I will have to tinker with some code and see what I can come
up with for non-constant case blocks! :)