Camelia

Terms

src
Most syntactic constructs in Perl 6 can be categorized in I<terms> and L<operators|/language/operators>. Here you can find an overview of different kinds of terms.

Literals

Int

    42
    12_300_00
    :16<DEAD_BEEF>

 
L<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

    12.34
    1_200.345_678

 
L<Rat> (rational numbers) literals 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 .. L<Range> operator).

Num

    12.3e-32
    3e8

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

Str

see the section on quoting constructs below.

Regex

see the section on quoting constructs below.

Pair

    a => 1
    'a' => 'b'
    :identifier
    :!identifier
    :identifier<value>
    :identifier<value1 value2>
    :identifer($value)
    :identifer['val1', 'val2']
    :identifier{key1 => 'val1', key2 => 'value2'}
    :$item
    :@array
    :%hash
    :&callable

 
L<Pair> objects can be created either with < infix:«= » >> (which auto-quotes the left-hand side if it is an identifier), or with the various colonpair forms. Those always start with a colon, and then are followed either by an identifier or the name of an already existing varible (whose name sans the sigil is used as the key, and value of the variable is used as the value of the pair). In the identifier form a colonpair, 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 >>.

Parcel

    ()
    1, 2, 3
    <a b c>
    «a b c»
    qw/a b c/

 
L<Parcel> literals are: the empty pair of parens () , a comma-separated list, or several quoting constructs

Quoting constructs

TODO

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:<fourty-two> { 42 };
    say fourty-two

 
or as constants
    constant forty-two = 42;
    say fourty-two

 

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 L<X::Syntax::NoSelf> is thrown.

now

Returns an L<Instant> object representing the current time.

rand

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

pi

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

e

Returns Euler's number

i

Returns the imaginary unit (for L<Complex> numbers).

Variables

Variables are discussed in L<variable language docs |/language/variables>.

Perl 6 Tricks and Treats newsletter

Register to the free newsletter now, and get updates and news.
Email:
Name: