lua-users home
lua-l archive

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

On Fri, Aug 19, 2011 at 11:41:09AM +0200, Lorenzo Donati wrote:
> On 19/08/2011 9.36, Dirk Laurie wrote:
> >
> > 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
> >
> Yes. It is. And I know that.
> Please, reread my post, it wasn't focused on sets (see the message 
> subject), but on general many-to-one mappings (of which a set may be 
> viewed as a particular case, if you consider the characteristic function 
> of the set as the mapping). I only mentioned sets as a trivial example.
OK, I have reread your post, and this time carefully noted the sentence
> Anyway even if it is a more stupid proposal than it seems to me, I hope
> to get new insights from whoever will be so kind to share an opinion.
and promise to be kind.

A less trivial example of the proposed syntax extension would be:

    tbl = { ['a','b','c']=good, [4,5,6]=bad, [7,'8','9']=so_so }

with `good`, `bad` and `so_so` already defined.  This suggests strongly
that tbl.a, tbl.b and tbl.c are to be initialized with the same value.
But in a later post, there is the suggestion that this could be 
implemented as syntactic sugar for 

    tbl['a']=good; tbl['b']=good; tbl['c']=good;
    tbl[4]=bad; tbl[5]=bad; tbl[6]=bad;
    tbl[7]=so_so; tbl['8']=so_so; tbl['9']=so_so;

Now, I take the following special case.

    tbl = { ['a','b','c']={}, [4,5,6]={}, [7,'8','9']={} }

This does not mean:

    tbl['a']={}; tbl['b']={}; tbl['c']={};
    tbl[4]={}; tbl[5]={}; tbl[6]={};
    tbl[7]={}; tbl['8']={}; tbl['9']={};

But shouldn't it sometimes mean that?  If tbl.a, tbl.b and tbl.c are  
initialized with the same table value, do we want them to refer
permanently to the actual same table?  In which case, why are there 
three items, not just one?  Or should they refer to different tables, 
that happen to have equal contents at the start?  Deep waters, ambiguity.

Now suppose, just suppose, that Lua allowed the Python-like syntax:

    a=b=c=1; d=e=f=2    --etc

Then it would be quite reasonable to ask that

    tbl = { a=b=c=good, [4]=[5]=[6]=bad, [7]=['8']=['9']=so_so }

also be legal.  

Should one not rather be lobbying for that extension?  


(who more than once wrote `a=10*[MyObject()]` in Python and debugged
for hours, in the days before deciding to switch to Lua)