lua-users home
lua-l archive

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


On Wed, Sep 23, 2015 at 9:23 AM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> On Wed, Sep 23, 2015 at 9:30 AM, John Hind <john.hind@zen.co.uk> wrote:
>> t = {["cat"], ["dog"]}  -- Shortcut for t = {["cat"] = true, ["dog"] = true}
>>
>> I've always wanted to extend this to:
>>
>> t = {[cat],[dog]}
>>
>> So, similarly to keys for methods, you can drop the quotes if the string is
>> a valid Lua name.
>
> if the idea of the patch is that omitted values default to `true`,
> then i'd say that the short form should be
>
> t = { cat, dog }
>
> because in normal Lua
>
> t = { cat=true, dog=true }
>
> is equivalent to
>
> t = { ['cat']=true, ['dog']=true }
>
> so if the `=true` part is optional, then you would be able to say either
>
> t = { ['cat'], ['dog'] }
>
> or
>
> t = { cat, dog }
>
> and the form {[cat], [dog]} would try to use the variables `cat` and `dog`

The form { cat, dog } is already well-defined (it creates a
two-element list containing the contents of the variables cat and
dog). The form should be { ['cat'], ['dog'] }.

/s/ Adam