It appears as if a scalar by itself is sort of a list of one item
If you explicitly apply a list operation to a scalar it behaves as if it were a list containing one element which is that scalar value.
What am I not understanding about the [] operator.
Indexing operations on a list (any Positional data structure; a List is a list but a list may not be a List) are checked according to the list's "shape", a list of "Indexing ranges".
You can only explicitly declare the indexing ranges of an Array.
# Value treated as list shape Indexing range
'a scalar value' (1) 0..0
(0,1,2) (*) 0..Inf
my @a (*) 0..Inf
my @b[42] (42) 0..41
(I'm slightly surprised by Lists (eg (0,1,2)
), which have immutable shape, being assigned a shape of (*)
. Why not (3)
(in the case of a 3 element list) if this is both known and immutable? (Perhaps it isn't?))