I was a bit surprised to see this:
> say my @i.so
False
> say my @i[3].so
True
Can anyone explain why, in raku, empty Arrays are falsey, yet empty shaped Arrays are truthy?
If the description "empty" refers to "no elements", then there's no such thing as an empty fixed-sized (aka "shaped") array:
say my @unshaped-array; # []
say @unshaped-array.shape; # (*) ("whatever" shape, or "unshaped")
say @unshaped-array.elems; # 0
say @unshaped-array.so; # False
say @unshaped-array[0,1,2]:exists; # (False False False)
say @unshaped-array[0,1,2]:delete; # ((Any) (Any) (Any))
say @unshaped-array[0,1,2]:exists; # (False False False)
say @unshaped-array; # []
say @unshaped-array = [Any,Any,Any]; # [(Any) (Any) (Any)]
say @unshaped-array.elems; # 3
say @unshaped-array.so; # True
say @unshaped-array[0,1,2]:exists; # (True True True)
say @unshaped-array[0,1,2]:delete; # ((Any) (Any) (Any))
say @unshaped-array[0,1,2]:exists; # (False False False)
say @unshaped-array; # []
say my @shaped-array[3]; # [(Any) (Any) (Any)]
say @shaped-array.shape; # (3)
say @shaped-array.elems; # 3
say @shaped-array.so; # True
say @shaped-array[0,1,2]:exists; # (False False False)
say @shaped-array[0,1,2]:delete; # (Nil Nil Nil)
say @shaped-array[0,1,2]:exists; # (False False False)
say @shaped-array; # [(Any) (Any) (Any)]
say @shaped-array = [42]; # [42 (Any) (Any)]
say @shaped-array.elems; # 3
say @shaped-array.so; # True
say @shaped-array[0,1,2]:exists; # (True False False)
say @shaped-array[0,1,2]:delete; # (42 Nil Nil)
say @shaped-array[0,1,2]:exists; # (False False False)
say @shaped-array = [Nil]; # [(Any) (Any) (Any)]
# Just because I named the array "shaped", doesn't mean its shape is fixed:
say @shaped-array := [Nil]; # [(Any)]
say @shaped-array.shape; # (*) ("whatever" shape, or "unshaped")
say @shaped-array := []; # []
say @shaped-array.elems; # 0
say @shaped-array.so; # False
my @i[0]; # Illegal ...
I don't know if there's currently a way to declare a variable that's permanently bound to a fixed shape array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With