[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: Ideas about colon operator syntax (and a patch in the work)
- From: "Thomas Jericke" <tjericke@...>
- Date: Tue, 29 Apr 2014 19:12:32 +0200
-----Original Message-----
> From: "Thomas Jericke" <tjericke@indel.ch>
> To: lua-l@lists.lua.org
> Date: 29-04-2014 17:06
> Subject: Re: Ideas about colon operator syntax (and a patch in the work)
>
> On 04/29/2014 04:54 PM, Luiz Henrique de Figueiredo wrote:
> > Your proposal is ambiguous. Consider this code:
> >
> > s = "I can shout!"
> > u = s:upper
> > ("hello"):gsub(".",print)
> >
> > Is the last line part of the second statement?
> >
I quickly tried it with the Lua 5.2.3 the statement
s = "I can shout!"
u = s:upper()
("hello"):gsub(".",print)
The last line is indeed part of the second statement unless you add a semicolon
to the end of the line. So actually I don't think the current version of
my patch changes anything about this problem.
>
> Your comment about the ambiguity is already answered by Daurminator ;-)
> I agree that my ideas doesn't solve the existing problem and maybe make
> it even worse.
I thought about this a little more. There is actually one situation more that
looks ambiguous (It only looks ambiguous, it actually isn't):
s = "I can shout!"
u = s:upper
"hello":gsub(".",print)
Again the same problem. The last line is still part of the second statement.
But at least there is one case where this is less ambiguous.
s = ""
u = s:upper
13.0 : integer -- no ambiguity here, while
u = s:upper()
(13.0) : integer () -- calls the result of s:upper() with 13.0 as argument.
The reason why this isn't ambiguous to me, is, that you just have to remember
one rule: In case a (....) statement can be either args or prefixexp it will
always be args. Thankfully Lua allows a semicolon to force (....) to be prefixexp if needed.
--
Thomas