Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^5: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)

by jcb (Parson)
on May 05, 2021 at 21:33 UTC ( [id://11132112] : note . print w/replies, xml ) Need Help??


in reply to Re^4: [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)
in thread [Raku] Assigning defaults to attributes that are fixed length lists (and other confusions)

An empty Array is falsey, yet an empty shaped Array is truthy

I will hazard a guess that Raku handles arrays in scalar context similarly to Perl 5: an array evaluated in scalar context produces the number of elements in the array. An empty array has zero elements, but a shaped array has a fixed number of elements. In boolean context, zero is false and any non-zero number is true.

Thus, an empty array (with zero elements) is a false value, but an array with a fixed non-zero number of elements is a true value.