lua-users home
lua-l archive

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


On Mon, Apr 12, 2010 at 4:00 PM, frank <frank@frankhirsch.net> wrote:
> Sam Roberts wrote:
>>>
>>> What's the easiest translation to convert the following c to lua? or do I
>>> have to make this into a if-else block.
>>>
>>> x = ((vXSTX > vXSX) || (vXSTX > vXSY)) ? (vXSX + vXSTX) : vXSX;
>>
>> x = ((vXSTX > vXSX) or (vXSTX > vXSY)) and (vXSX + vXSTX) or vXSX
>
> This is the surely the most compact translation.
>
> But if someone asks for the easiest translation of a one-line code
> snippet, should you give them the ol' short circuit trickery, or do
> you consider they might be better off with something less compact,
> and more... easy and transparent?

Sure, if you assume they have C code, and either can't read it, and
don't know that lua has an "if-else" statement. Which is possible, I
guess.

Me, I assume they have C code, know what it means, and can't figure
out how to write something so compact in lua, and can't believe that
one line of C needs to be translated to six lines of lua:

local x
if this and that then
  x = those
else
 x = some other
end

I was pretty happy when I finally found out that "x and y or z" was
essenttially "x ? y : z", maybe Cynthia is, too.

Cheers,
Sam