lua-users home
lua-l archive

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


On Wed, Apr 9, 2014 at 11:37 PM, steve donovan
<steve.j.donovan@gmail.com> wrote:
> On Thu, Apr 10, 2014 at 8:16 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> I'm happier with the notion that `x,y,z in tbl` is just a synonym for
>> `tbl.x, tbl.y, tbl.z`. The above would be better described by
>> { 'a', 'b', 'c' }[1,2,3] -- but let's not hijack this thread.
>
> Yes, we have the (modified) Peter patch where the statement
>
> [local] x,y,z in tbl
>
> is [local] x,y,z = tbl.x, tbl.y, tbl.z
>
> (modulo temporary for expressions)
>
> and Coroutines is suggesting (in addition?) that
>
> x,y,z in tbl
>
> is a multi-valued expression meaning tbl.x,tbl.y,tbl.z
>
> The first is straightforward, convenient and easy to explain. The
> second - I don't know; it would lead to rather obscure code.  We
> should not feel compelled to do everything in one statement, after all
> (leads to some of the more unreadable Python idioms).
>

I'm suggesting that "x, y, z in some_table" be the base expression to
generate a vararg from a table by a list of key identifiers (I'm still
unsure about indexing by objects too: 1, 'cat' in some_table)

Ideally, '[local] x, y, z in tbl' would an extension of that
(syntactic sugar) for '[local] x, y, z = x, y, z in tbl'.  I'm
suggesting that the 'in' expression be made more general for creating
varargs from tables anywhere, rather than just possible for
declarations.

The only other confusion I see is that 'in' makes it sound like we're
checking for the existence of something within a table, which would
lead newcomers to think it's a boolean evaluation.

`from' would be clearer even though it invites a new keyword:

x, y, z from tbl
[local] x, y, z from tbl

'as' could be considered as well to mitigate the difficulty parsing this:

tbl as x, y, z
[local] tbl as x, y, z -- a bit unclear, though