lua-users home
lua-l archive

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


On Sat, Nov 20, 2010 at 12:52 PM, David Kastrup <dak@gnu.org> wrote:
> Nilson <nilson.brazil@gmail.com> writes:
>
>> As today seems to be the day to talk about Lua's syntax enhancements,
>> I would like to talk about another one:
>>
>> "Quaternary operator"
>>
>> [ <exp>; true_result; false_result; nil_result ]
>
Ah!

One more "con":

- Inside table construction, the QOP will force the compiler to work a
little more (the compiler will need to look ahead the symbol after the
first element.inside the open bracket to decide if the square bracket
means a index or QOP).

   a = {   [1] = '10' }  and  a = {   [exp;1;2] = '10' }

but

One more "pro":

- Inside table construction, you might write a conditional construction:

   a = {  1,2, [A_FLAG; 3], 4  }

If the A_FLAG is false, the compiler could:

a) recognize this construction as a conditional insertion, then:
print a[3]
4

b) treat QOP as a regular statement, then:
print a[3]
nil

-- 
Nilson