Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding colon pairs with numbers, including non-latin
  • Loading branch information
JJ committed Jan 6, 2019
1 parent c5cec61 commit af50a52
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions doc/Language/syntax.pod6
Expand Up @@ -643,13 +643,14 @@ a real and an imaginary number:
=begin code :skip-test
1+2i
6.123e5i # note that this is 6.123e5 * i and not 6.123 * 10 ** (5i)
6.123e5i # note that this is 6.123e5 * i, not 6.123 * 10 ** (5i)
=end code
=head3 Pair literals
L<Pairs|/type/Pair> are made of a key and a value, and there are two basic forms for
constructing them: C<< key => 'value' >> and C<:key('value')>.
L<Pairs|/type/Pair> are made of a key and a value, and there are two
basic forms for constructing them: C<< key => 'value' >> and
C<:key('value')>.
=head4 Arrow pairs
Expand All @@ -667,24 +668,34 @@ like-an-identifier-ain't-it => 42
Short forms without explicit values:
=begin code
my $thing = 42;
:$thing # same as thing => $thing
:thing # same as thing => True
:!thing # same as thing => False
=end code
=begin code
my $thing = 42;
:$thing # same as thing => $thing
:thing # same as thing => True
:!thing # same as thing => False
=end code
The variable form also works with other sigils, like C<:&callback> or
C<:@elements>.
C<:@elements>. If the value is a number literal, it can also be
expressed in this short form:
:42thing # same as thing => 42
:٤٢thing # same as thing => 42
This order is inverted if you use another alphabet
:٤٢ث # same as ث => ٤٢
the I<thaa> letter precedes the number.
Long forms with explicit values:
=begin code :skip-test
:thing($value) # same as thing => $value
:thing<quoted list> # same as thing => <quoted list>
:thing['some', 'values'] # same as thing => ['some', 'values']
:thing{a => 'b'} # same as thing => { a => 'b' }
=end code
=begin code :skip-test
:thing($value) # same as thing => $value
:thing<quoted list> # same as thing => <quoted list>
:thing['some', 'values'] # same as thing => ['some', 'values']
:thing{a => 'b'} # same as thing => { a => 'b' }
=end code
=head3 Array literals
Expand All @@ -695,27 +706,29 @@ inside:
say ['a', 'b', 42].join(' '); # OUTPUT: «a b 42␤»
# ^^^^^^^^^^^^^^ Array constructor
If the constructor is given a single L<Iterable|/type/Iterable>, it'll clone and flatten it.
If you want an C<Array> with just 1 element that is that C<Iterable>, ensure
to use a comma after it:
If the constructor is given a single L<Iterable|/type/Iterable>, it'll
clone and flatten it. If you want an C<Array> with just 1 element that
is that C<Iterable>, ensure to use a comma after it:
my @a = 1, 2;
say [@a].perl; # OUTPUT: «[1, 2]␤»
say [@a,].perl; # OUTPUT: «[[1, 2],]␤»
The C<Array> constructor does not flatten other types of contents.
Use the L<Slip|/type/Slip> prefix operator (C<|>) to flatten the needed items:
The C<Array> constructor does not flatten other types of contents. Use
the L<Slip|/type/Slip> prefix operator (C<|>) to flatten the needed
items:
my @a = 1, 2;
say [@a, 3, 4].perl; # OUTPUT: «[[1, 2], 3, 4]␤»
say [|@a, 3, 4].perl; # OUTPUT: «[1, 2, 3, 4]␤»
=head3 Hash literals
A leading associative sigil and pair of parenthesis C<%( )> can surround a C<List> of
C<Pairs> to form a L<Hash|/type/Hash> literal; typically there is a comma-delimited
C<List> of C<Pairs> inside. If a non-pair is used, it is assumed to be a key and
the next element is the value. Most often this is used with simple arrow pairs.
A leading associative sigil and pair of parenthesis C<%( )> can surround
a C<List> of C<Pairs> to form a L<Hash|/type/Hash> literal; typically
there is a comma-delimited C<List> of C<Pairs> inside. If a non-pair is
used, it is assumed to be a key and the next element is the value. Most
often this is used with simple arrow pairs.
say %( a => 3, b => 23, :foo, :dog<cat>, "french", "fries" );
# OUTPUT: «a => 3, b => 23, dog => cat, foo => True, french => fries␤»
Expand All @@ -741,7 +754,8 @@ Note that with objects as keys, you cannot access non-string keys as strings:
=head3 Regex literals
A L<Regex|/type/Regex> is declared with slashes like C</foo/>. Note that this C<//> syntax is shorthand for the full C<rx//> syntax.
A L<Regex|/type/Regex> is declared with slashes like C</foo/>. Note that
this C<//> syntax is shorthand for the full C<rx//> syntax.
=begin code :skip-test
/foo/ # Short version
Expand All @@ -753,9 +767,9 @@ A L<Regex|/type/Regex> is declared with slashes like C</foo/>. Note that this C<
=head3 Signature literals
Signatures can be used standalone for pattern matching, in addition to the
typical usage in sub and block declarations. A standalone signature is declared
starting with a colon:
Signatures can be used standalone for pattern matching, in addition to
the typical usage in sub and block declarations. A standalone signature
is declared starting with a colon:
say "match!" if 5, "fish" ~~ :(Int, Str); # OUTPUT: «match!␤»
Expand Down

0 comments on commit af50a52

Please sign in to comment.