|
-----Original Message-----
From: "Michael Richter" <ttmrichter@gmail.com>
To: "Lua mailing list" <lua-l@lists.lua.org>
Date: 01-05-2014 07:35
Subject: Re: Ideas about colon operator syntax (and a patch in the work)
On 29 April 2014 20:49, Thomas Jericke <tjericke@indel.ch> wrote:The first change is simple and I have already a patch for it, I can release it as single patch if someone is interested.
This change simply makes the function call brackets optional if there is no argument, other than self which is implicitly added.
This means you can write:
require "string"
local text = "I can shout!"
print(text:upper) --> I CAN SHOUT!
I think this change is quite useful for the following reasons:
- No ambiguity: The : operator outside a function declaration like "function table:funct() ... end" already defines a function call, no need to define it twice with empty brackets.
I disagree here. If you encounter foo:bar() in text now, does it mean foo.bar(foo) or does it mean foo.bar(foo)()? (Keep in mind that bar can return a function after all.)
Operant order is very normal concept of language design. Learning the operant order of a programing language is something you need to do anyway. The decision whether (funct1 "Text" : funct2) should be evaluated from left to right or the other way around is no different from the question whether (1 + 4 * 2) should be evaluated from left to right or the other way around. Do you really want to say, that any language where is 4 * 1 is evaluated before 1 + 4 is adding cognitive load to the user?To me this seems to be ambiguous, meaning you have to have some arbitrary rule to determine which meaning is intended. I prefer explicit behaviour than implicit behaviour surrounded by arbitrary rules.Anyway, with the first step already done I am now trying to handle the "hello":function and 1.6:function to work.
I am not sure how much I want to allow. Especially in this case:
print( lower "I'm getting loud with you !" : upper)
What should happen? Synstax error, print "I'M GETTING LOUD WITH YOU!", or "i'm getting loud with you!"?
As soon as you find yourself asking this question in a language design, personally I think it's time to back out and look at your goals. No matter how you answer this you're adding unnecessarily (IMO) to the cognitive load of the user in exchange for dubious statements about "readability" (when you actually likely mean "ease of typing" since programmers typically have a fetish for not typing for some reason).