lua-users home
lua-l archive

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

On 09/10/15 08:17 AM, Rena wrote:

On Oct 9, 2015 6:41 AM, "Thomas Jericke" < <>> wrote:
> On 10/09/2015 12:48 AM, Nagaev Boris wrote:
>> t[[[z]]] looks ambiguous. Everybody would have to remember what it
>> means: t("z") or t["z"].
> t[[z]] is t("z") so t[[[]]] would actually be t("[]"), wouldn't it?
> --
> Thomas

Yeah, this syntax is ambiguous. t [[[z]]] already looks like it could be parsed as one of:
t["z"] -- replacing innermost [[]] with ""
t"[z"] -- replacing first [[ and ]] with ""
t"[z]" -- replacing outermost [[]] with ""

As far as neatness, I think spaces improve it a lot here by clearly defining the intended meaning:
t[ [[z]] ] -- or even:
    [[some long string here]]
But of course spaces don't matter to the compiler.

My solution if I were presented with this situation would be one of:
local s=[[z]]
X = t[s]
Or: refactor so that indexing a table with a string that doesn't fit nicely in quotes is no longer necessary. :)

Table initialization.

Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.