lua-users home
lua-l archive

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


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"

It is // and "a // b" means the same as defined(a) ? a : b. So you can write
things like this:

a //= b // c // d

to give a the first defined value in this chain. In Lua 4.0, "or" works just
fine for this purpose, which I really liked. Maybe this new boolean type is
more trouble than it's worth?

Eric

> -----Original Message-----
> From: owner-lua-l@tecgraf.puc-rio.br
> [mailto:owner-lua-l@tecgraf.puc-rio.br]On Behalf Of Peter Shook
> Sent: Wednesday, January 09, 2002 9:38 PM
> To: Multiple recipients of list
> Subject: nil isn't as unique in Lua 4.1
>
>
>
> I'd rather not have the boolean type because then there will be a need
> for functions like Perl's 'defined' (to tell if a variable is not nil)
> and 'exists' (to tell if a table has a value for a particular key).  How
> else with you be able to tell if a variable is false or nil?
>
> In Lua 4.0, it is simple to delegate to another table:
>
>   x = t1[i] or t2[i]
>
> If element i isn't in table t1, try t2.  But in 4.1, if t1[i] is false,
> then this expression will access t2 when you don't really want it to.  I
> don't want to see Lua start looking like this:
>
>   $x = exists $t1{$i} ? $t1{$i} : $t2{$i} ;
>
> - Peter
>