lua-users home
lua-l archive

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


 
Sets as plain-jane Lua tables like {alpha=1,beta=2} remain attractive,
since there's no magic wrapper needed.

One man's attractive Jeanne is another man's plain Jane!  I find that table
as unattractive in the context of sets as I find a table with holes in the context
of the standard table library.
 
The wrapper ensures that 'true' is the only value, so that s1+s2 and s2+s1
are copies of the same table.  It will also allow tstring to render a set as
"set{2,3,5,7,11}" instead of "{[5]=true,[7]=true,[2]=true,[11]=true,[3]=true}".

If you allow any Lua table as input to so-called "set" functions, there is too
much ambiguity for a general-purpose library.

How would you define the union of {alpha=1,beta=2} and {alpha='a',beta='b'}?

The only application I can see right now for non-constant values is
a multiset, in which beta=2 would mean there are two betas in stock.
It has the interesting property that 0 would mean there are none right now,
but there were before, whereas nil would mean there never was any.