Skip to content

Commit 53cbdb8

Browse files
committed
(paritially) document class Variable
1 parent bebee61 commit 53cbdb8

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

htmlify.p6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ sub url-munge($_) {
3333
my @menu =
3434
('language','' ) => (),
3535
('type', 'Types' ) => <basic composite domain-specific exceptions>,
36-
('routine', 'Routines' ) => <sub method term operator>,
36+
('routine', 'Routines' ) => <sub method term operator trait>,
3737
# ('module', 'Modules' ) => (),
3838
# ('formalities','' ) => ();
3939
;

lib/Type/Variable.pod

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
=begin pod
2+
3+
=TITLE class Variable
4+
5+
=SUBTITLE Object representation of a variable for use in traits
6+
7+
class Variable { ... }
8+
9+
Variables have a wealth of compile-time information, but at run time, accesses
10+
to to a variable usually act on the value stored inside the variable, not the
11+
variable itself.
12+
13+
Class C<Variable> holds the compile-time information that traits can use to
14+
introspect and manipulate variables.
15+
16+
=head1 Routines
17+
18+
=head2 method name
19+
20+
method name(Variable:D: str)
21+
22+
Returns the name of the variable, including the sigil.
23+
24+
=head2 trait is default
25+
26+
multi sub trait_mod:<is>(Variable:D, :$default!)
27+
28+
Sets the default value with which a variable is initialized, and to which it
29+
is reset when Nil is assigned to it.
30+
31+
my Int $x is default(42);
32+
say $x; # 42
33+
$x = 5;
34+
say $x; # 5
35+
# explicit reset:
36+
$x = Nil;
37+
say $x; # 42
38+
39+
=head2 trait is dynamic
40+
41+
multi sub trait_mod:<is>(Variable:D, :$dynamic)
42+
43+
Marks a variable as dynamic, that is, accessible from inner dynamic scopes
44+
without being in an inner lexical scope.
45+
46+
=begin code :allow<B L>
47+
sub introspect() {
48+
say B<$CALLER::x>;
49+
}
50+
my $x B<is dynamic> = 23;
51+
introspect; # 23
52+
{
53+
# not dynamic
54+
my $x;
55+
introspect() # dies with an exception of L<type X::Caller::NotDynamic|/type/X::CallerNotDynamic>
56+
}
57+
=end code
58+
59+
=end pod

0 commit comments

Comments
 (0)