Skip to content

Commit

Permalink
Correction for @ coercer
Browse files Browse the repository at this point in the history
- It does more than just remove the Scalar
- Show <> decont methodop
- Show a bug where using `@` instead of `<>` leaks memory
  • Loading branch information
zoffixznet committed Nov 28, 2017
1 parent 2ed89df commit c047f87
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion doc/Language/containers.pod6
Expand Up @@ -283,11 +283,20 @@ As hinted above, scalar containers prevent that flattening:
my @a = 1, 2, 3;
say f $@a, 4, 5; # OUTPUT: «3␤»
The C<@> character can also be used as a prefix to remove a scalar container:
The C<@> character can also be used as a prefix to coerce the argument to a list, thus removing a scalar container:
my $x = (1, 2, 3);
.say for @$x; # 3 iterations
However, the C«<>» is more appropriate to decontainerize items that aren't
lists:
my $x = ^Inf .grep: *.is-prime;
say "$_ is prime" for @$x; # WRONG! List keeps values, thus leaking memory
say "$_ is prime" for $x<>; # RIGHT. Simply decont the Seq
my $y := ^Inf .grep: *.is-prime; # Even better; no Scalars involved at all
Methods generally don't care whether their invocant is in a scalar, so
my $x = (1, 2, 3);
Expand Down

0 comments on commit c047f87

Please sign in to comment.