lua-users home
lua-l archive

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


On 06/12/2015 02:29 AM, Tim Hill wrote:
On Jun 11, 2015, at 5:26 AM, Rodrigo Azevedo <rodrigoams@gmail.com> wrote:

REASONING

There are uncountable examples of "methods" that do not need an argument, for example

led[1]:blink
arm[2].pos[3]:go
z:abs
z:Re
polynomial:diff
etc

PROPOSAL

Raise the "methods" syntactic sugar ":" to a function call without arguments, with the exception of the ubiquitous "self", namely, call "methods" without the common usage of  '(' ')', or '{' '}' or ' " ' ' " '.

But what does this really give you? You can type “x:foo” instead of “x:foo()”. This doesn’t seem like much of a pay-back for making the language harder to read. At the moment it’s pretty clear when a function/method is called. All this patch does is make that more obscure so that you can save a tiny bit of typing.

—Tim



I have made this patch as well. Not the proposal though, as I am indeed sceptical if this would be a good change in vanilla. My arguing back than was (and still is) that there are many cases where the readability is actually better with less brackets.

The reason I had the idea for the syntax change in the first place, was to be able to nicely call converter functions on the caller side.

Here an example:
dosomecoolstuff(tonumber(astring), auserdata:tonumber(), tostring(anumber))

what I'd liked to have was:

dosomecoolstuff(astring : number, auserdata : number, anumber : string, 45 : deg2rad)

Which I find more readable, and more consistent.
I would then have added the metamethods (number, string, etc) to all the types I needed to convert.

Also your argument that function calls are clear is not true. Lua already drops the () for single string and single table arguments.

print "I am a call!"

So there are calls without a pair of (), and to make it worse there are a lot of (some stuff here) which aren't a call. Now even I don't agree with the readability, I still don't think the introduction of a x:f syntax is necessary enough to add it to vanilla.
--
Thomas