Skip to content

Commit fd36457

Browse files
committed
Added Introspection section to Scalar
Specifically the "name", "default" and "dynamic" methods were not documented yet. And the "of" was buried in documentation about atomic ops. Felt right to create a separate Introspection section
1 parent 289c0ce commit fd36457

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

doc/Type/Scalar.pod6

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,52 @@ Therefore, there would be a race to do that binding. The C<Scalar> atomic
109109
operations will never check for or do any such auto-vivification, so as to
110110
make such bugs much more evident (rather than only observed under stress).
111111
112+
=head1 Introspection
113+
114+
=head2 method of
115+
116+
method of(Scalar:D: --> Mu)
117+
118+
Returns the type constraint of the container.
119+
120+
Example:
121+
122+
my Cool $x = 42;
123+
say $x.VAR.of; # OUTPUT: «(Cool)»
124+
125+
=head2 method default
126+
127+
method default(Scalar:D: --> Str)
128+
129+
Returns the default value associated with the container.
130+
131+
Example:
132+
133+
my $x is default(666) = 42;
134+
say $x.VAR.default; # OUTPUT: «666»
135+
136+
=head2 method name
137+
138+
method name(Scalar:D: --> Str)
139+
140+
Returns the name associated with the container.
141+
142+
Example:
143+
144+
my $x = 42;
145+
say $x.VAR.name; # OUTPUT: «$x»
146+
147+
=head2 method dynamic
148+
149+
method dynamic(Scalar:D: --> Bool)
150+
151+
Returns whether the variable is visible in dynamic variable lookups.
152+
153+
Example:
154+
155+
my $*FOO = 42;
156+
say $*FOO.VAR.dynamic; # OUTPUT: «True»
157+
112158
=head1 Routines
113159
114160
=head2 atomic-assign
@@ -207,17 +253,6 @@ manner as follows:
207253
This will reliably build up a linked list of 4000 items, with 4 nodes with
208254
each value ranging from 0 up to 999.
209255
210-
=head2 method of
211-
212-
method of(Scalar:D: --> Mu)
213-
214-
Returns the type constraint of the container.
215-
216-
Example:
217-
218-
my Cool $x = 42;
219-
say $x.VAR.of.^name; # OUTPUT: «Cool»
220-
221256
=head1 Operators
222257
223258
=head2 infix ⚛=

0 commit comments

Comments
 (0)