lua-users home
lua-l archive

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



On Wed, Sep 11, 2013 at 6:10 PM, Andres Perera <andres.p@zoho.com> wrote:

Almost the same as perl's // operator, except // does not treat nil (undef) the same as false

Typo, it's the perl || operator, in fact // treats ONLY undef as false. This is done so you can apply the idiom when the actual value is '' or 0:

$ perl -MData::Dumper -e 'print Dumper [ 0 || 1, undef ||1, 0//1, undef // 1 ]'
$VAR1 = [
          1,
          1,
          0,
          1
        ];

( Think on the line being applied as '$actual op $default', or as my $value = shift op $default on subroutine entry )

Francisco Olarte.