lua-users home
lua-l archive

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


Soni They/Them L. <fakedme@gmail.com> wrote:

>> Otherwise, for the example you gave... just use if/else in the first place,
>> or only use non-constant or non-conflicting values as case values?
>> 
>> ~Paige
> 
> Why not make it explicit? If you want the constant cases to come first,
> put the constant cases first?

Due to the nature of how the switch/case works the case values would have
to be broken down into two distinct categories; constant and non-constant.
I would say that the constant value case blocks have priority as they are
known at compile time and are explicitly declared, the non-constant ones
therefore would be checked after the constant ones... were I to implement
the ability to have non-constant case blocks at all.

With the example you gave you could just use an if/else statement. The idea
of switch/case, and the way I implemented it, is not just to be syntactic
sugar for if/else blocks but to offer more performance when selecting code
paths from many known-at-compile-time options.

I like the idea of being able to specify non-constant case values, however,
there will have to be some limitations due to the nature of the problem.
Also, arguably, once you start executing functions to obtain case values
the entire point of switch/case, the speed improvement, goes away as well.

~Paige