lua-users home
lua-l archive

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




On 06/05/15 01:27 PM, Hisham wrote:
On 6 May 2015 at 13:13, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
PS. I still like syntax "hello":sub(1, 4)
I always wondered: is there a reason why this syntax is not supported?
Because to allow it in general would require unbounded lookahead.
Consider for instance:
         "x".."x".."x".."x".."x".."x".."x".."x".."x".."x".."x":sub(1, 4)
It would? I would assume that : binds tighter than .., as in:

Lua 5.3.0  Copyright (C) 1994-2015 Lua.org, PUC-Rio
function f(s) return s:upper() end
f "hello" .. "world"
HELLOworld
The current solution with parentheses solves this and is fully general.
It's probaly easy to allow just this syntax <string literal> : <function call>,
but not general enough.
But it is just as general as `f "hello"`, isn't it?

To clarify, I wasn't asking about `:` on arbitrary expressions, only
on string literals.

-- Hisham

What about table constructors as in `return {init = function(self, ...) return self end}:init()`? (I also wish we could `{...}[3]` and `#...` (and `...[3]`?), but that's a different thing)

--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.