lua-users home
lua-l archive

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


On Thu, 10 Jan 2002, Eric Ries wrote:

> I'm afraid that, if Lua goes down this path, we will have the need for
> Perl6's "defined-shortcut-operator" which works "like || but with a twist"

I think that, more often than not, you know what type of object you
are expecting. So, if you are expecting numbers, or tables, or strings,
you still can use the "or" to select the first "defined" value.

In the few cases that a false is among the possible outcomes, then we
will have to go through the pain of writing "if a == nil then ... ".

Notice that Lua already has a similar situation: the code

  (a and b) or c

is equivalent to "a ? b : c", provided that b is not nil (or false, now).
Again, frequently we know that b cannot be nil, and so the idiom works fine.

-- Roberto