Perl 6 Terms

Most syntactic constructs in Perl 6 can be categorized in terms and operators.

Here you can find an overview of different kinds of terms.




Int literals consist of digits and can contain underscores between any two digits.

To specify a base other than ten, use the colonpair form :radix<number> .



Rat literals (rational numbers) contain two integer parts joined by a dot.

Note that trailing dots are not allowed, so you have to write 1.0 instead of 1. (this rule is important because there are infix operators starting with a dot, for example the .. Range operator).



Num literals (floating point numbers) consist of Rat or Int literals followed by an e and a (possibly negative) exponent. 3e8 constructs a Num with value 3 * 10**8.


'a string'
'I\'m escaped!'
"I don't need to be"
"\"But I still can be,\" he said."
q|Other delimiters can be used too!|

String literals are most often created with ' or ", however strings are actually a powerful sub-language of Perl 6. See Quoting Constructs.


/ match some text /
rx/slurp \s rest (.*$/

These forms produce regex literals. See Quoting Constructs.


=> 1
'a' => 'b'
:identifier<value1 value2>
:identifier{key1 => 'val1'key2 => 'value2'}

Pair objects can be created either with infix:«=>» (which auto-quotes the left-hand side if it is an identifier), or with the various colon-pair forms. Those almost always start with a colon and then are followed either by an identifier or the name of an already existing variable (whose name without the sigil is used as the key and value of the variable is used as the value of the pair). There is a special form where an integer value is immediately after the colon and the key is immediately after the value.

In the identifier form of a colon-pair, the optional value can be any circumfix. If it is left blank, the value is Bool::True. The value of the :!identifier form is Bool::False.

If used in an argument list, all of these forms count as named arguments, with the exception of 'quoted string' => $value .


<a b c>
«a b c»
qw/a b c/

List literals are: the empty pair of parentheses (), a comma-separated list, or several quoting constructs.

term *

Creates an object of type Whatever. See Whatever documentation for more details.

Identifier terms

There are built-in identifier terms in Perl 6, which are listed below. In addition one can add new identifier terms with the syntax:

sub term:<forty-two> { 42 };
say forty-two

or as constants:

constant forty-two = 42;
say forty-two;

term self

Inside a method, self refers to the invocant (i.e. the object the method was called on). If used in a context where it doesn't make sense, a compile-time exception of type X::Syntax::NoSelf is thrown.

term now

Returns an Instant object representing the current time. It includes leap seconds and as such a few dozen seconds larger than time:

say (now - time).Int# OUTPUT: «37␤» 

term time

Returns the current POSIX time as an Int. See now for high-resolution timestamp that includes leap seconds.

term rand

Returns a pseudo-random Num in the range 0..^1.

term π

Returns the number π, i.e., the ratio between circumference and diameter of a circle. The ASCII equivalent of π is pi.

term pi

Returns the number π, i.e., the ratio between circumference and diameter of a circle. pi is the ASCII equivalent of π.

term τ

Returns the number τ, i.e., the ratio between circumference and radius of a circle. The ASCII equivalent of τ is tau.

term tau

Returns the number τ, i.e., the ratio between circumference and radius of a circle. tau is the ASCII equivalent of τ.

term e

Returns Euler's number.

term i

Returns the imaginary unit (for Complex numbers).


Variables are discussed in the variable language docs.


Constants are declared with constant, followed by an identifier and do not require a sigil. The right-hand side is evaluated at compile time, therefore being possibly too early to make sense.

constant SpeedOfLight = 299792458;     # m/s 
constant PHI          = 1.61803398875# The golden ratio is everywhere! 
constant POW2 = do { my int @table@table = 124 ... 2**32@table };
say POW2[16];
# OUTPUT: «65536␤» 

Since constant's right-hand side is evaluated at compile time, their usage within modules could lead to unexpected behavior, please see the related traps section.

Constants are our-scoped by default, but adding my would make them lexical:

constant SpeedOfLight = 186200;
constant Unit         = 'mi/s';
    my constant SpeedOfLight  = 299_792_458;
    my constant Unit          = 'm/s';
    my constant Source        = 'wikipedia';
    say 'Speed of Light is ' ~ SpeedOfLight ~ ' ' ~ Unit;
say 'Speed of Light is ' ~ SpeedOfLight ~ ' ' ~ Unit;
# here 'wikipedia' is out of scope ! 

that will produce the following output (note how the constants have been lexically overwritten):

Speed of Light is 299792458 m/s
Speed of Light is 186200 mi/s

Referencing a lexical constant outside of the block will produce an Undeclared name compilation error.