3 ms·
I'd suggest not painting yourself into a corner where your map has to be either key/value or an array. Lua got this right, most other languages didn't. It's a
by samatman 4y ago
I'd suggest not painting yourself into a corner where your map has to be either key/value or an array.
Lua got this right, most other languages didn't.
It's an anti-feature, especially from a data modeling perspective. Treating indices as implicit is good, pretending integer indices are special, and must be separated from all other sorts of mapping, is not.
Consider that Lua can express XML without making up a fake key for children:
{tag = xml, attr = {...}, child1, child2, child3}
- specialist 4y agoTotally agree. In my hobby DSL, those inlined childX are syntactic sugar for parent{ children=[child1, child2, child3]}. More generally, I remain uncomfortably undecided about named params (pairs) and indexed params. Esp wrt constructors. IIRC, I spotted a (hobby?) language that permitted both indexed params (matched in order per method signature) and named params, plus default values. So given "method( int a=10, int b=20)" you could invoke as "method( 1, 2 )", out of order like "method( b: 2, a: 1)" or partially like "method( b: 2 )". Riffing a bit, this could then allow passing a map of params to a method. Code construction wise, that looks like passing around a context object. I'll look at Lua again. (It's been a minute.) Thanks.