Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Hopefully clarify that Perl 6 doesn't have references better
  • Loading branch information
lizmat committed Jun 12, 2018
1 parent 961110a commit dc1ea46
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions doc/Language/5to6-nutshell.pod6
Expand Up @@ -443,17 +443,19 @@ so we will have to focus on the intent of the reference operators
instead of the actual syntax.
=for code :lang<perl5>
my $aref = \@aaa ; # Perl 5
my $aref = \@aaa ; # Perl 5
This might be used for passing a reference to a routine, for instance. But in Perl 6, the default behavior is a pass by reference.
This might be used for passing a reference to a routine, for instance. But in
Perl 6, the (single) underlying object is passed (which you could consider
to be a sort of pass by reference).
=begin code
my @a = 4,8,15;
(-> @array { @array[0] = 66})(@a);
say @a; # OUTPUT: «[66 8 15]␤»
my @array = 4,8,15;
{ $_[0] = 66 }(@array); # run the block with @array aliased to $_
say @array; # OUTPUT: «[66 8 15]␤»
=end code
The declared C<@a> is passed by reference, and its first value modified inside the declared routine.
The underlying Array object of C<@array> is passed, and its first value modified inside the declared routine.
In Perl 5, the syntax for dereferencing an entire reference is the
type-sigil and curly braces, with the reference inside the curly braces. In Perl 6, this concept simply does not apply, since the I<reference> metaphor does not really apply.
Expand Down

0 comments on commit dc1ea46

Please sign in to comment.