[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: The += operator, again
- From: Philippe Verdy <verdyp@...>
- Date: Thu, 6 Dec 2018 06:50:12 +0100
Shouldn't that be simply Foobar.add(value) if we assume they're no member named "add" but it is defined via the metatable __index method? And shouldn't there exist a way to cleanly refer to a member via its __index metamethod rather than its defined index, using a simpler form such as: Foobar->add(value) which would ignore any value assigned to Foobar['add']? We could then have a distinction between actual members and metamembers coming from a prototype. This would mean adding support for __proto in the metatable, allowing us to support not just classes but interfaces.
One place where I think that “++” or equivalent might be as syntactic sugar for adding something to the end of a list
As shorthand for
But it’s not that big a deal
> On Dec 5, 2018, at 5:50 PM, David Favro <email@example.com> wrote:
> I have been an advocate for the += operator, which I think is sorely lacking in Lua, for many years . But in my opinion ++ and -- are much less useful, and when used give fewer advantages , and pose more issues, such as already being used for comments. Yet for some reason people can't help lumping them all together and then using the issues with the unary operators as a purported complication of the binary operator, as well as increasing the overall size of the addition to the language, leading to objections of 'bloat'.
> -- David
> : I mean in core Lua. I consider patches and forks to be vastly less useful.
> : ++ and -- are very frequently used in languages such as C for loop iteration. In Lua, iteration takes place much more often via ipairs(), and even the numeric for loop does not require explicit increment. Furthermore, the ++ operator in C often compiles to a distinct hardware instruction; while in the Lua VM, it would presumably generate code no different than "x+=1" .