Skip to content

Commit

Permalink
(paritially) document class Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Jan 19, 2015
1 parent bebee61 commit 53cbdb8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion htmlify.p6
Expand Up @@ -33,7 +33,7 @@ sub url-munge($_) {
my @menu =
('language','' ) => (),
('type', 'Types' ) => <basic composite domain-specific exceptions>,
('routine', 'Routines' ) => <sub method term operator>,
('routine', 'Routines' ) => <sub method term operator trait>,
# ('module', 'Modules' ) => (),
# ('formalities','' ) => ();
;
Expand Down
59 changes: 59 additions & 0 deletions lib/Type/Variable.pod
@@ -0,0 +1,59 @@
=begin pod
=TITLE class Variable
=SUBTITLE Object representation of a variable for use in traits
class Variable { ... }
Variables have a wealth of compile-time information, but at run time, accesses
to to a variable usually act on the value stored inside the variable, not the
variable itself.
Class C<Variable> holds the compile-time information that traits can use to
introspect and manipulate variables.
=head1 Routines
=head2 method name
method name(Variable:D: str)
Returns the name of the variable, including the sigil.
=head2 trait is default
multi sub trait_mod:<is>(Variable:D, :$default!)
Sets the default value with which a variable is initialized, and to which it
is reset when Nil is assigned to it.
my Int $x is default(42);
say $x; # 42
$x = 5;
say $x; # 5
# explicit reset:
$x = Nil;
say $x; # 42
=head2 trait is dynamic
multi sub trait_mod:<is>(Variable:D, :$dynamic)
Marks a variable as dynamic, that is, accessible from inner dynamic scopes
without being in an inner lexical scope.
=begin code :allow<B L>
sub introspect() {
say B<$CALLER::x>;
}
my $x B<is dynamic> = 23;
introspect; # 23
{
# not dynamic
my $x;
introspect() # dies with an exception of L<type X::Caller::NotDynamic|/type/X::CallerNotDynamic>
}
=end code
=end pod

0 comments on commit 53cbdb8

Please sign in to comment.