Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

152 lines (106 sloc) 4.294 kb
=begin pod
=TITLE Glossary of Perl 6 terminology
=head1 Anonymous
A subroutine, method or submethod is called I<anonymous> if it can't
be called by name.
# named subroutine
sub double($x) { 2 * $x };
# anonymous subroutine, stored in a named scalar
my $double = sub ($x) { 2 * $x };
Note that it is still allowed to have a name
# anonymous, but knows its own name
my $s = anon sub triple($x) { 3 * $x }
say $; # triple
=head1 Autothreading
Autothreading is what happens if you pass a junction to a sub that
expects a parameter of type C<Any> or a subtype thereof. The call is
executed multiple times, each time with a different eigenstate of the
junction. The result of these calls is assembled in a junction of the
same type as the original junction.
sub f($x) { 2 * $x };
if f(1|2|3) == 4 {
say 'success';
Here C<f()> is a sub with one parameter, and since it has no explicit
type, it is implicitly typed as C<Any>. The C<Junction> argument causes
the C<f(1|2|3)> call to be internally executed as C<f(1)|f(2)|f(3)>,
and the resulting junction is C<2|4|6>. This process of separating
Junction arguments into multiple calls to a function is called
=head1 Instance
An I<instance> of a class is also called an I<object> in some other
programming languages. It has a storage for attributes, and is often
the return value of a call to a method called C<new>, or a literal.
Instances of most types are defined to be C<True>
i.e., C<defined($instance)> is C<True>.
my Str $str = "hello"; ## this is with builtin types, e.g. Str
if defined($str) {
say "Oh, yeah. I'm defined.";
} else {
say "No. Something off? ";
## if you wanted objects...
class A {
# nothing here for now.
my $an_instance =;
say $an_instance.defined.perl;# defined($an_instance) works too.
Or to put it another way, a class has all the blueprint of methods and
attributes, and an instance carries it forward into the real world.
=head1 Invocant
The object on which a method is called is called the I<invocant> in Perl 6.
It is what C<self> refers to in a method.
say 'str'.uc; # 'str' is the invocant of method uc
=head1 Literal
A I<literal> is a piece of code that directly stands for a (often
built-in) object, and also refers to the object itself.
my $x = 2; # the 2 is a literal
say $x; # $x is not a literal, but a variable
=head1 lvalue
An I<lvalue> or a I<left value> is anything that can appear on the left
hand side of the assignment operator C<=>; anything you can assign
Typical lvalues are variables, private and C<is rw> attributes, lists
of variables and lvalue subroutines.
Examples of lvalues:
Declaration lvalue Comments
my $x; $x
my ($a, $b); ($a, $b)
has $!attribute; $!attribute Only inside classes
has $.attrib is rw; $.attrib
sub a is rw { $x }; a()
Examples of things that are not lvalues
3 # literals
constant x = 3; # constants
has $.attrib; # attributes; you can only assign to $!attrib
sub f { }; f(); # "normal" subs are not writable
sub f($x) { $x = 3 }; # error - parameters are read-only by default
=head1 Mainline
The C<mainline> is the program text that is not part of any kind of block.
use v6; # mainline
sub f {
# not in mainline, in sub f
f(); # in mainline again
=head1 Slurpy
A parameter of a sub or method is said to be I<slurpy> if it can
consume an arbitrary number of arguments. It is indicated by an
asterisk C<*> in front of the parameter name.
sub sum (*@numbers) {
return [+] @numbers;
=head1 Type Object
A I<type object> is an object representing a class, role, package,
grammar or enum. It is generally accessible with the same name as
the type.
class A { };
say A; # A is the type object
my $x =; # same here
my $x = class {
method greet() {
say "hi";
# $x now holds a type object returned from the
# anonymous class definition
=end pod
Jump to Line
Something went wrong with that request. Please try again.