Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor corrections and reflow
  • Loading branch information
JJ committed Jan 11, 2019
1 parent 2424e62 commit 800a5b9
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions doc/Language/variables.pod6
Expand Up @@ -50,7 +50,7 @@ Examples:
my %hash = London => 'UK', Berlin => 'Germany';
X<|is (type of variable)>
The type to which the variable will be bound, can be set with C<is> in the
The type to which the variable will be bound can be set with C<is> in the
declaration of the variable. Assuming we have a C<FailHash> class:
class FailHash is Hash {
Expand All @@ -68,7 +68,7 @@ declaration of the variable. Assuming we have a C<FailHash> class:
One can then define a C<%h> variable using C<is>:
=for code :preamble<class FailHash {}>
my %h is FailHash = oranges => "round", bananas => "bendy";
my %h is FailHash = oranges => "round", bananas => "bendy";
And then run the following code:
Expand Down Expand Up @@ -139,12 +139,17 @@ assignment expression is parsed as C<@array = (($num = 42), "str")>, because
item assignment has tighter precedence than the comma. However, let's see what
happens if the internal variable assignment is in a list context:
my ( @foo, $bar );
@foo = ($bar) = 42, "str"; # list assignment for $bar: uses parentheses
say @foo.perl; # OUTPUT: «[(42, "str"),]␤» (an Array)
say $bar.perl; # OUTPUT: «$(42, "str")␤» (a List)#
=for code
my ( @foo, $bar );
@foo = ($bar) = 42, "str"; # list assignment for $bar: uses parentheses
say @foo.perl; # OUTPUT: «[(42, "str"),]␤» (an Array)
say $bar.perl; # OUTPUT: «$(42, "str")␤» (a List)#
In this case, C<()> is the list contextualizer, putting the assignment to C<$bar> in a list context; C<$bar> then I<decides> to include all the items to the right hand side of the C<=> sign; this is still included in a list assignment to C<@foo>, which then becomes an array with a single element, a C<List>.
In this case, C<()> is the list contextualizer, putting the assignment to
C<$bar> in a list context; C<$bar> then I<decides> to include all the items to
the right hand side of the C<=> sign; this is still included in a list
assignment to C<@foo>, which then becomes an array with a single element, a
C<List>.
See L<operators|/language/operators> for more details on precedence.
Expand All @@ -166,8 +171,8 @@ you've defined it:
θ = 3; # Dies with the error "Cannot modify an immutable Num"
=end code
Sigilless variables do not enforce context, so they can be used to pass
something on as-is:
Sigilless variables do not enforce L<context|/language/contexts>, so they can be
used to pass something on as-is:
sub logged(&f, |args) {
say('Calling ' ~ &f.name ~ ' with arguments ' ~ args.perl);
Expand Down

0 comments on commit 800a5b9

Please sign in to comment.