Raku confusing postfix ,= operator behavior

foo ,= bar

is short for

foo = foo, bar

So,

@a ,= 3

is short for:

@a = @a, 3;

During the Great List Refactor in 2015, the single argument rule became active everywhere. Since the right hand side of the expression is not a single argument, the @aon the right hand side, will not get flattened.

So effectively, you're creating a self-referential Array, in which the first element refers to itself (which is what the say is trying to tell you).

For reasons I'm not too clear about anymore, the same does not apply to objects doing the Associative role. So in that case, the %a does get flattened, thereby adding the given Pair to the Hash.

my %a = :11a, :22b;
%a = %a, :33x;
say %a # OUTPUT: «{a => 11, b => 22, x => 33}␤»

To get back to your question: in the case of an Array, I don't think there is much use for the ,= operation. Before the Great List Refactor, it may have done what you expected. But it would have been inconsistent with other situations, and consistency was deemed more important (because before the Great List Refactor, when something would flatten and when not, was rather arbitrary and many times a source of WAT instead of DWIM).

Tags:

Operators

Raku