lua-users home
lua-l archive

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


On 20/08/2011 21.10, Dirk Laurie wrote:
On Fri, Aug 19, 2011 at 05:29:53PM +0200, Lorenzo Donati wrote:

I think syntax should not be designed with the focus of simplifying
writing code. The design goal should be simplifying *reading* code.


Remember that Luiz once said:

     A language does not grow in a healthy way by adding things
     for which you cannot find a reason to omit.

The remark made the OP lose his temper, but the philosophy behind it is
what has kept Lua lean and hungry through seventeen years of development.

So one must always weigh the a new proposal against the way one would
implement it at present, and decide whether it is so much more readable
and so much more convenient and so much more efficient that its advantages
outweigh the disadvantage of making Lua bigger.

I fully agree! That's why I started this thread and didn't complain directly to Lua team that Lua hasn't my favourite toy built-in ;-)


[...]

But Tony's implementation in current Lua is not too far behind
(although I'm not overfond of the name `flatten_keys`:

     -- see his post for the definition of `flatten_keys`
     f = flatten_keys { [{1,2,3,5,7,11,13,17,19,23}] = 1,
           [{4,6,8,10,12,14,16,18,20,22,24}] = 2,
           [{9,15,21}] = 3,
           [25] = 5 }

Uh?!? Cool!

Clearly I have missed Tony's message ... (checking) ... ach! It went In the trashbin by mistake! My bad! I should be more careful pressing "del" when doing housecleaning :-(


as is the similar idea with inverted tables:

That's my current approach, indeed.

[...]

Well, Tony's approach is really much clearer, and very similar to my initial proposal, no much more cluttered: just a function call and a couple of braces per entry. I think I will definitely add it to my Lua trick mental drawer! :-)

I said in some other post, about the fact of newbies being criticized on lua-l, that *I learned something* almost every time I was criticized! How true! :-)

The only drawback of Tony's approach is that it generates some garbage tables (as the inverse map approach). Not significant though, unless you have to generate many mappings in a tight loop.

That would be the only remaining advantage of my proposal. Not a big deal, to be honest.


There seems to be no reason to omit the proposed syntax extension. ;-)

Well, it seems I can put *my proposal* in the trashbin, now :-)
unless Lua team realized it was cool, it could be achieved with 5- lines of C code and brings great speed improvements to Lua :-)))

Thanks for the feedback (and making me resurrect Tony's message!)


Dirk


--Lorenzo