> The Raku idea is that an operator only does one thing.
Its kind of interesting that Raku’s own docs think of '=' being used for both item assignment and lost assignment as an exception to this, because it illustrates how narrowly Raku defines “one thing”. (As does the use of different postcircumfix operators for positional and associative access, which most languages call indexing, and use one construct for, which may not even technically be an operator.)
But its not just freedom to create new operators that allows this; for it to work Raku has a huge number of built-in basic operators, plus the hyper- and meta-operators.
Actually `=` sort-of only does one thing. It asks the left argument what it wants to do with the values.
my @a = 1,2,3;
is almost the same as
my @a;
@a.VAR.STORE((1,2,3));
---
As for separate positional and associative access:
Raku has separate positional and named arguments to functions.
An argument list is actually a singular thing called a Capture. Even if it usually pretends to not be.
my \capture = \( 'a', b => 10 ); # Capture litteral
say capture[0]; # a
say capture{'b'}; # 10
sub foo ( |capture ) {
say capture[0]; # a
say capture{'b'}; # 10
}
foo |capture; # give it the above capture litteral
# foo 'a', b => 10
sub bar ( $a, :$b ){
say $a; # a (positional)
say $b; # 10 (named)
}
bar |capture; # give it the above capture litteral
# bar 'a', b => 10
To be able to easily extract out those parts, it helps if there is a different way to get at each.
The same thing also applies to extracting information out of regexes
'a10' ~~ / (.) # $0
$<b> = (..) # $<b>
/;
say $0; # a
say $<b>; # 10
say $/[0]; # a (positional index into $/)
say $/{'b'}; # 10 (named index into $/)
Its kind of interesting that Raku’s own docs think of '=' being used for both item assignment and lost assignment as an exception to this, because it illustrates how narrowly Raku defines “one thing”. (As does the use of different postcircumfix operators for positional and associative access, which most languages call indexing, and use one construct for, which may not even technically be an operator.)
But its not just freedom to create new operators that allows this; for it to work Raku has a huge number of built-in basic operators, plus the hyper- and meta-operators.