Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
uzluisf committed Nov 22, 2018
2 parents ef50b8a + cfb6e81 commit 6d865bb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 70 deletions.
27 changes: 15 additions & 12 deletions doc/Language/operators.pod6
Expand Up @@ -439,7 +439,8 @@ element of C<*> will repeat its 2nd last element indefinitely.
my @l = <a b c d> Z~ ':' xx *; # RESULT: «<a: b: c: d:>»
@l = <a b c d> Z~ 1, 2, *; # RESULT: «<a1 b2 c2 d2>»
If an infix operator is not given, C<,> (comma operator) will be used by default:
If an infix operator is not given, the C<,> (comma operator) will be used by
default:
my @l = 1 Z 2; # RESULT: «[(1 2)]»
Expand All @@ -465,10 +466,9 @@ compiler understand you.
=head2 term C«< >»
The X<quote-words|qw;quote-words> construct breaks up the contents on whitespace and returns
a L<List|/type/List> of the words. If a word
looks like a number literal or a C<Pair> literal, it's converted to the
appropriate number.
The X<quote-words|qw;quote-words> construct breaks up the contents on whitespace
and returns a L<List|/type/List> of the words. If a word looks like a number
literal or a C<Pair> literal, it's converted to the appropriate number.
say <a b c>[1]; # OUTPUT: «b␤»
Expand All @@ -492,12 +492,14 @@ being interpreted as a named argument.
L<Block> or L<Hash> constructor.X<|block constructor;hash constructor>
If the content is empty, or contains a single list that starts with a L<Pair> literal or
C<%>-sigiled variable, and the L«C<$_> variable|/syntax/$_» or placeholder parameters are
not used, the constructor returns a L<Hash>. Otherwise it constructs a L<Block>.
If the content is empty, or contains a single list that starts with a L<Pair>
literal or C<%>-sigiled variable, and the L«C<$_> variable|/syntax/$_» or
placeholder parameters are not used, the constructor returns a L<Hash>.
Otherwise it constructs a L<Block>.
To force construction of a L<Block>, follow the opening brace with a semicolon.
To always ensure you end up with a L<Hash>, you can use C<%( )> coercer or L<hash> routine instead:
To always ensure you end up with a L<Hash>, you can use C<%( )> coercer or
L<hash> routine instead:
{}.^name.say; # OUTPUT: «Hash␤»
{;}.^name.say; # OUTPUT: «Block␤»
Expand Down Expand Up @@ -576,15 +578,16 @@ in custom types.
=head2 postcircumfix C«<>»
Decontainerization operator, which extracts the value from a container and makes it independent of the container type.
Decontainerization operator, which extracts the value from a container and makes
it independent of the container type.
=begin code
use JSON::Tiny;
my $config = from-json('{ "files": 3, "path": "/home/perl6/perl6.pod6" }');
say $config.perl; # OUTPUT: «${:files(3), :path("/home/perl6/perl6.pod6")}»
say $config.perl; # OUTPUT: «${:files(3), :path("/home/perl6/perl6.pod6")}»
my %config-hash = $config<>;
say %config-hash.perl; # OUTPUT: «{:files(3), :path("/home/perl6/perl6.pod6")}»
say %config-hash.perl; # OUTPUT: «{:files(3), :path("/home/perl6/perl6.pod6")}»
=end code
It's a C<Hash> in both cases, and it can be used like that; however, in the
Expand Down
10 changes: 5 additions & 5 deletions doc/Language/py-nutshell.pod6
Expand Up @@ -316,11 +316,11 @@ Perl 6
Using C<if> as a statement modifier (as above) is acceptable
in Perl 6, even outside of a list comprehension.
The C<yield> statement in Python which produces a
C<generator> is like a C<gather>, C<take> construct
in Perl 6. These both print 1, 2, 3.
The C<yield> statement within a C<for> loop in Python, which produces a
C<generator>, is like a C<gather>/C<take> construct in Perl 6. These both print
1, 2, 3.
Python
I<Python>
=begin code :lang<python>
def count():
Expand All @@ -331,7 +331,7 @@ for c in count():
print c
=end code
Perl 6
I<Perl 6>
sub count {
gather {
Expand Down
33 changes: 16 additions & 17 deletions doc/Language/regexes.pod6
Expand Up @@ -115,16 +115,14 @@ written with an upper-case letter, C<\W>.
=head3 X<C<\n> and C<\N>|regex,\n;regex,\N>
C<\n> matches a single, logical newline character.C<\N> matches a single
C<\n> matches a single, logical newline character. C<\N> matches a single
character that's not a logical newline.
What is considered as a single newline character is defined via the compile
time variable L«C<$?NL>|/language/variables#index-entry-$?NL», and the
L<newline pragma|/language/pragmas>.
Therefore, C<\n> is supposed to be able to match either a Unix-like
newline C<"\n">, a Microsoft Windows style one C<"\r\n">, or one in the Mac
style C<"\r">.
What is considered as a single newline character is defined via the compile time
variable L«C<$?NL>|/language/variables#index-entry-$?NL», and the
L<newline pragma|/language/pragmas>; therefore, C<\n> is supposed to be able to
match either a Unix-like newline C<"\n">, a Microsoft Windows style one
C<"\r\n">, or one in the Mac style C<"\r">.
=head3 X<C<\t> and C<\T>|regex,\t;regex,\T>
Expand All @@ -148,8 +146,8 @@ Examples for horizontal whitespace characters are
U+2001 EM QUAD
=end code
Vertical whitespace like newline characters are explicitly excluded; those
can be matched with C<\v>, and C<\s> matches any kind of whitespace.
Vertical whitespace such as newline characters are explicitly excluded; those
can be matched with C<\v>; C<\s> matches any kind of whitespace.
=head3 X<C<\v> and C<\V>|regex,\v;regex,\V>
Expand Down Expand Up @@ -259,7 +257,7 @@ L<C<uniprop>|/routine/uniprop>:
"a".uniprop('Block'); # OUTPUT: «Basic Latin␤»
"a" ~~ / <:Block('Basic Latin')> /; # OUTPUT: «「a」␤»
These are the unicode general categories used for matching:
These are the Unicode general categories used for matching:
=begin table
Expand Down Expand Up @@ -343,7 +341,7 @@ whitespace.
"αβγ" ~~ /<[\c[GREEK SMALL LETTER ALPHA]..\c[GREEK SMALL LETTER GAMMA]]>*/;
Within the C«< >» you can use C<+> and C<-> to add or remove multiple range
definitions and even mix in some of the unicode categories above. You can also
definitions and even mix in some of the Unicode categories above. You can also
write the backslashed forms for character classes between the C<[ ]>.
/ <[\d] - [13579]> /;
Expand Down Expand Up @@ -527,7 +525,9 @@ instance here:
# 0 => 「ACT」
# 1 => 「An interesting chain」)
Although in this case, eliminating the C<:> from behind C<**> would make it behave exactly in the same way. The best use is to create I<tokens> that will not be backtracked:
Although in this case, eliminating the C<:> from behind C<**> would make it
behave exactly in the same way. The best use is to create I<tokens> that will
not be backtracked:
$_ = "ACG GCT ACT IDAQT";
say m:g/[(\w+:) \s*]+ (\w+) $$/;
Expand Down Expand Up @@ -780,10 +780,9 @@ two leading spaces each.
=head2 X«Word boundary|regex, <|w>;regex, <!|w>»
To match any word boundary, use C«<|w>» or C«<?wb>». This is similar to
X«C<\b>|regex deprecated,\b» of other languages.
To match not a word boundary, use C«<!|w>» or C«<!wb>». This is similar to
X«C<\B>|regex deprecated,\B» of other languages.
X«C<\b>|regex deprecated,\b» in other languages. To match the opposite, any
character that is not bounding a word, use C«<!|w>» or C«<!wb>». This is similar
to X«C<\B>|regex deprecated,\B» in other languages.
These are both zero-width regex elements.
Expand Down
45 changes: 38 additions & 7 deletions doc/Language/subscripts.pod6
Expand Up @@ -898,23 +898,54 @@ sense, so don't feel compelled to implement it. If you don't, users will
get an appropriate error message when they try to bind to a positional slot
of an object of this type.
=head2 method STORE
=head3 method STORE
=comment When modifying this section, please also adapt the STORE
section in Associative accordingly as they are very similar.
method STORE (::?CLASS:D: \values, :$initialize)
This method should only be supplied if you want to support the:
This method should only be supplied if you want to support this syntax:
=for code :preamble<role Foo {}>
my @a is Foo = 1,2,3;
my @a is Foo = 1,2,3;
syntax for binding your implementation of the C<Positional> role.
Which is used for binding your implementation of the C<Positional> role.
Should accept the values to (re-)initialize the object with. The optional
named parameter will contain a C<True> value when the method is called on
the object for the first time. Should return the invocant.
C<STORE> should accept the values to (re-)initialize the object with. The
optional named parameter will contain a C<True> value when the method is called
on the object for the first time. It should return the invocant.
=begin code
class DNA {
has $.chain is rw;
method STORE ($chain where {
$chain ~~ /^^ <[ACGT]>+ $$ / and
$chain.chars %% 3
}, :$initialize --> DNA) {
if $initialize {
self= DNA.new( chain => $chain )
} else {
self.chain = $chain;
self
}
}
method Str(::?CLASS:D:) { return $.chain.comb.rotor(3) }
};
my @string is DNA = 'GAATCC';
say @string.Str; # OUTPUT: «((G A A) (T C C))␤»
@string = 'ACGTCG';
say @string.Str; # OUTPUT: «((A C G) (T C G))␤»
=end code
This code takes into account the value of C<$initialize>, which is set to
C<True> only if we are assigning a value to a variable declared using the C<is>
syntax for the first time. The C<STORE> method should set the C<self> variable
an return it in all cases, including when the variable has already been
initialized.
=head2 Methods to implement for associative subscripting
Expand Down

0 comments on commit 6d865bb

Please sign in to comment.