lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On 2018-01-28 01:58 PM, Paige DePol wrote:
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! :)

Can you use goto across elseif yet?

if x then
  goto ::y::
elseif y then
  ::y::
end

If not, that could be an interesting syntax extension. Only across a single elseif tho.


~Paige



--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.