lua-users home
lua-l archive

Re: RFE: table ctor syntax enhancement for many-to-one mappings

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


On Thu, Aug 18, 2011 at 10:46:27PM +0200, Lorenzo Donati wrote:
> 
> I stumbled into this idea while writing a long set-like table. Wouldn't 
> it be nice if the follwing:
> 
> 
> set = { a = true, b = true, [1] = true }
> 
> could be abbreviated as:
> 
> set = { ["a","b",1] = true }
> 
Uh-oh. Bad timing. We've just been directed on another thread
to <http://en.wikipedia.org/wiki/Parkinson%27s_Law_of_Triviality>,
which refers to Wadler's Law:
 the bulk of discussion on programming language design centers 
 around syntax (which, for purposes of the argument is considered 
 a solved problem), as opposed to semantics.
But to return to your point: surely this is a Lua idiom?
 set = {}
 for _,v in ipairs{"a","b",1} do set[v]=true end
The part that grows when the set is large, i.e. {"a","b",1},
is exactly the same size as in the proposal. The one-off part
is bigger, but the same code can also be used to add more elements 
to the set later.
 
Dirk

AltStyle によって変換されたページ (->オリジナル) /