lua-users home
lua-l archive

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



-----Original Message----- 
> From: "steve donovan" <steve.j.donovan@gmail.com> 
> To: "Lua mailing list" <lua-l@lists.lua.org> 
> Date: 01-05-2014 15:59 
> Subject: Re: Ideas about colon operator syntax (and a patch in the work) 
> 
> On Thu, May 1, 2014 at 3:34 PM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> >> The idea is from Ada.
> > That explains a lot. In fact, it explains everything.
> 
> I don't know the girl in question, but I do know her mother Pascal,
> and cousin Eiffel.  It's considered a feature that functions/methods
> of no arguments require no parentheses.  Betrand Meyer argues that it
> allows o.f to be implemented as a field or a function, without the
> implementer being constrained or the user needing to know[1]
> 

Yes, this is also the reason why Ada uses the () for array index, so you don't
need to know if object.items(2) is an index of array "items" or a call to the
getter function "items" with the argument 2.

> But in a language with first-class function values it makes no sense.
> o.f is the value of the field 'f' of 'o';  if it is a function, then
> we have to apply an explicit call operator to it.  With Thomas'
> proposal, this remains true; but the odd construction 'o:f' on its own
> has an implicit call operator.
Could you please stop calling it a proposal. You make it look as I wish that
this becomes part of vanilla Lua, while I am not even sure if my
patch will work at all.

I totally agree with your reasoning that o.f() must have a call operator.
There is actually one reason more - at least for me - that the call must be
explicit: You may only now at runtime if f is a function or not. In a static
language, you easily can decide (as programmer or parser) if f is a function or
not. In Lua you can't, only at runtime you can.

Now with the : operator this is totally different. The result of the : operator is
not a first-class citizen. You can not write 
local method = a:f
method()

When you see the : operator, you know it is either a function call or
declaration. It is actually even clearer than brackets.
("hello") can be a function call or an expression depending on the context.
> 
> I think this inconsistency would be hard to explain to anyone
> encountering it for the first time.
> 
That's already the case. The : operator is inconsistent and the use of
the colon operator is hard to explain as it is now. I often get calls from
customers who ask me: "When do I have to use the ':' operator?"

Maybe it's just because I dislike the colon operator as it is now in Lua that I don't
have scruple to mess around with it ;-)

Again I want to emphasize that this is not a proposal for Lua,
I try to make a patch and looked for some input, and this list contains
the people with which can give the right inputs for this ideas. 
And actually I got some interesting input regarding the order of computation.
--
Thomas