lua-users home
lua-l archive

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





-----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.)

By my current definition there is no ambiguity here. The brackets are optional, which means, if there are brackets the belong to the operator.
This rule must be there because of backwards compatibility. Therefore foo:bar() always means  foo.bar(foo) and never  foo.bar(foo)()
There is absolutely no ambiguity here as long as you want to be backward compatible.

The idea is from Ada. So this is not something I came up with myelf.
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).
 
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?

Do we really wan't to write polynoms as (2 * x) + (4 * (x ^ 2)) + (3 * (x^3)) instead of 2 * x  +  4 * x^2 + 3 * x^3 ?
I don't and as long as you don't want that either, you will have to live with the fact that you will have to learn the operator order of a programming language.
--
Thomas