Skip to content

Commit aa2eb63

Browse files
committed
Adds information on 'bareword' Pair declaration, closes #2520
1 parent 6aa90da commit aa2eb63

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

doc/Type/Pair.pod6

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ There are many syntaxes for creating C<Pair>s:
2020
:key<value1 value2>; # But this is key => <value1 value2>
2121
:foo(127); # short for foo => 127
2222
:127foo; # the same foo => 127
23+
24+
You can also use an I<identifier-like literal> as key; this will not need the
25+
quotes as long as it follows the syntax of
26+
L<ordinary identifiers|/syntax/%20identifiers.html#Ordinary_identifiers>:
27+
2328
(foo => 127) # the same foo => 127
2429
2530
Variants of this are
@@ -62,9 +67,9 @@ Any variable can be turned into a C<Pair> of its name and its value.
6267
say $p; # OUTPUT: «bar => 10␤»
6368
6469
65-
It is worth noting that when assigning a L<Scalar|/type/Scalar> as value of a C<Pair>
66-
the value holds the container of the value itself. This means that it is possible to change the
67-
value from outside of the C<Pair> itself:
70+
It is worth noting that when assigning a L<Scalar|/type/Scalar> as value of a
71+
C<Pair> the value holds the container of the value itself. This means that it is
72+
possible to change the value from outside of the C<Pair> itself:
6873
6974
=begin code
7075
my $v = 'value A';
@@ -75,12 +80,13 @@ $v = 'value B';
7580
$pair.say; # OUTPUT: a => value B
7681
=end code
7782
78-
Please also note that this behavior is totally unrelated to the way used to build the C<Pair> itself
79-
(i.e., explicit usage of C<new>, use of colon, fat arrow), as well as if the C<Pair> is bound
80-
to a variable.
83+
Please also note that this behavior is totally unrelated to the way used to
84+
build the C<Pair> itself (i.e., explicit usage of C<new>, use of colon, fat
85+
arrow), as well as if the C<Pair> is bound to a variable.
8186
82-
It is possible to change the above behaviour forcing the C<Pair> to remove the scalar container
83-
and to hold the effective value itself via the method L<freeze|/type/Pair#method_freeze>:
87+
It is possible to change the above behaviour forcing the C<Pair> to remove the
88+
scalar container and to hold the effective value itself via the method
89+
L<freeze|/type/Pair#method_freeze>:
8490
8591
=begin code
8692
my $v = 'value B';
@@ -116,18 +122,19 @@ it and checks invocant's value C<.ACCEPTS> that value:
116122
say %(:42a) ~~ :42a; # OUTPUT: «True␤»
117123
say %(:42a) ~~ :10a; # OUTPUT: «False␤»
118124
119-
If C<topic> is another L<Pair|/type/Pair>, checks the invocant's value C<.ACCEPTS> the
120-
C<topic's> value. Note that the keys are not considered and can be different:
125+
If C<topic> is another L<Pair|/type/Pair>, checks the invocant's value
126+
C<.ACCEPTS> the C<topic's> value. Note that the keys are not considered and can
127+
be different:
121128
122129
say :42a ~~ :42a; # OUTPUT: «True␤»
123130
say :42z ~~ :42a; # OUTPUT: «True␤»
124131
say :10z ~~ :42a; # OUTPUT: «False␤»
125132
126133
If C<topic> is any other value, uses the invocant's key as the name of the
127134
method to call on C<topic> and check's its L«C<.Bool>|/routine/Bool» is the same
128-
as C<.Bool> of the invocant's value. This form can be used to check L<Bool|/type/Bool> values
129-
of multiple methods on the same object, such as L<IO::Path>, by using
130-
L<Junctions|/type/Junction>:
135+
as C<.Bool> of the invocant's value. This form can be used to check
136+
L<Bool|/type/Bool> values of multiple methods on the same object, such as
137+
L<IO::Path>, by using L<Junctions|/type/Junction>:
131138
132139
say "foo" .IO ~~ :f & :rw; # OUTPUT: «False␤»
133140
say "/tmp".IO ~~ :!f; # OUTPUT: «True␤»

0 commit comments

Comments
 (0)