Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make examples compile
  • Loading branch information
Altai-man committed Aug 14, 2016
1 parent 61d6d56 commit edbad25
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 191 deletions.
56 changes: 11 additions & 45 deletions doc/Type/Int.pod6
Expand Up @@ -4,14 +4,15 @@
=SUBTITLE Integer (arbitrary-precision)
class Int is Cool does Real {}
=for code :skip-test
class Int is Cool does Real { }
C<Int> objects store integral numbers of arbitrary size. C<Int>s are immutable.
There are two main syntax forms for C<Int> literals
123 # Int in decimal notation
:16<BEEF> # Int in radix notations
123; # Int in decimal notation
:16<BEEF>; # Int in radix notations
For your convenience common radix forms come with a prefix shortcut.
Expand All @@ -21,10 +22,10 @@ For your convenience common radix forms come with a prefix shortcut.
All forms allow underscores between any two digits which can serve as visual
separators, but don't carry any meaning:
5_00000 # five Lakhs
500_000 # five hundred thousand
0xBEEF_CAFE # a strange place
:2<1010_1010> # 0d170
5_00000; # five Lakhs
500_000; # five hundred thousand
0xBEEF_CAFE; # a strange place
:2<1010_1010>; # 0d170
=head1 Methods
Expand All @@ -35,31 +36,21 @@ Defined as:
multi sub chr(Int:D ) returns Str:D
multi method chr(Int:D:) returns Str:D
Usage:
chr INTEGER
INTEGER.chr
Returns a one-character string, by interpreting the integer as a Unicode
codepoint number and converting it to the corresponding character.
Example:
65.chr # returns "A"
196.chr # returns "Ä"
65.chr; # returns "A"
196.chr; # returns "Ä"
=head2 routine expmod
Defined as:
multi sub expmod(Int:D: Int $y, Int $mod) returns Int:D
multi sub expmod(Int $y, Int $mod) returns Int:D
multi method expmod(Int:D: Int $y, Int $mod) returns Int:D
Usage:
expmod(INTEGER, POWER, MODULUS)
INTEGER.expmod(POWER, MODULUS)
Returns the given C<Int> raised to the C<$y> power within modulus C<$mod>.
say expmod(4, 2, 5); # 1
Expand All @@ -71,10 +62,6 @@ Defined as:
method polymod(Int:D: +@mods)
Usage:
INTEGER.polymod(LIST)
Returns a sequence of mod results corresponding to the divisors in C<@mods>.
The divisors are given from smallest "unit" to the largest
(e.g. 60 seconds per minute, 60 minutes per hour) and the results
Expand Down Expand Up @@ -128,12 +115,6 @@ Defined as:
multi sub is-prime (Int:D $number) returns Bool:D
multi method is-prime (Int:D:) returns Bool:D
Usage:
is-prime INTEGER
INTEGER.is-prime
Returns C<True> if this C<Int> is known to be a prime, or is likely to be a
prime based on a probabilistic Miller-Rabin test.
Expand All @@ -149,11 +130,6 @@ Defined as:
multi method lsb(Int:D:)
multi sub lsb(Int:D)
Usage:
lsb INTEGER
INTEGER.lsb
Returns L<Nil|/type/Nil> if the number is 0. Otherwise returns the zero-based
index from the right of the least significant (rightmost) 1 in the binary
representation of the number.
Expand All @@ -171,11 +147,6 @@ Defined as:
multi method msb(Int:D:)
multi sub msb(Int:D)
Usage:
msb INTEGER
INTEGER.msb
Returns L<Nil|/type/Nil> if the number is 0. Otherwise returns the zero-based
index from the right of the most significant (leftmost) 1 in the binary
representation of the number.
Expand All @@ -193,11 +164,6 @@ Defined as:
multi sub unival(Int:D) returns Numeric
multi method unival(Int:D:) returns Numeric
Usage:
unival INTEGER
INTEGER.unival
Returns the number represented by the Unicode codepoint with the given integer
number, or L<NaN|/type/Num#NaN> if it does not represent a number.
Expand Down
84 changes: 25 additions & 59 deletions doc/Type/Map.pod6
Expand Up @@ -4,7 +4,8 @@
=SUBTITLE Immutable mapping from strings to values
class Map does Associative is Iterable { }
=for code :skip-test
class Map does Associative is Iterable { }
A Map is an immutable mapping from string keys to values of arbitrary
types. It serves as a base class for L<Hash>, which is mutable.
Expand All @@ -26,29 +27,26 @@ return them always in the same order when called on the same object.
Defined as:
proto method new(*@, *%) {*}
proto method new(*@, *%)
multi method new(*@args, *%pairs)
Usage:
Map.new(ARGS)
Creates a new Map from a list of alternating keys and values, with
the same semantics as described for hash assigning in the L<Hash>
documentation.
my %map = Map.new('a', 1, 'b', 2);
=head2 method elems
Defined as:
method elems(Map:D:) returns Int:D:
Usage:
MAP.elems
method elems(Map:D:) returns Int:D
Returns the number of pairs stored in the Map.
my %map = Map.new('a', 1, 'b', 2);
say %map.elems; # 2
=head2 method ACCEPTS
Defined as:
Expand All @@ -58,10 +56,6 @@ Defined as:
multi method ACCEPTS(Map:D: Regex $topic)
multi method ACCEPTS(Map:D: Any $topic)
Usage:
MAP.ACCEPTS(TOPIC)
Used in smart-matching if the right-hand side is an C<Map>.
If the topic is list-like (L<Positional>), returns True if
Expand All @@ -79,13 +73,16 @@ behavior is applied.
To retrieve a value from the Map by key, use the C<{ }> postcircumfix
operator:
my $value = $map{$key};
my $map = Map.new('a', 1, 'b', 2);
say $map{'a'}; # 1
To check whether a given key is stored in a Map, modify the access
with the C<:exists> adverb:
if %h{$key}:exists {
say "%h{} has key $key";
my $map = Map.new('a', 1, 'b', 2);
my $key = 'a';
if $map{$key}:exists {
say "$map{} has key $key";
}
=head2 method keys
Expand All @@ -94,46 +91,39 @@ Defined as:
method keys(Map:D:) returns List:D
Usage:
MAP.keys
Returns a list of all keys in the Map.
my $m = Map.new('a' => (2, 3), 'b' => 17);
say $m.keys; # (a b)
=head2 method values
Defined as:
method values(Map:D:) returns List:D
Usage:
MAP.values
Returns a list of all values in the Map.
my $m = Map.new('a' => (2, 3), 'b' => 17);
say $m.values; # ((2 3) 17)
=head2 method pairs
Defined as:
method pairs(Map:D:) returns List:D
Usage:
MAP.pairs
Returns a list of all pairs in the Map.
my $m = Map.new('a' => (2, 3), 'b' => 17);
say $m.pairs; # (a => (2 3) b => 17)
=head2 method antipairs
Defined as:
method antipairs(Map:D:) returns Seq:D
Usage:
MAP.antipairs
Returns all keys and their respective values as a L<Seq|/type/Seq> of C<Pair>s
where the keys and values have been exchanged, i.e. the opposite of method
L<pairs|#method_pairs>. Unlike the L<invert|#method_invert> method, there is
Expand All @@ -148,10 +138,6 @@ Defined as:
method invert(Map:D:) returns Seq:D
Usage:
MAP.invert
Returns all keys and their respective values as a L<Seq|/type/Seq> of C<Pair>s
where the keys and values have been exchanged. The difference between C<invert>
and L<antipairs|#method_antipairs> is that C<invert> expands list values into
Expand All @@ -166,24 +152,16 @@ Defined as:
method kv(Map:D:) returns List:D
Usage:
MAP.kv
Returns a list of keys and values interleaved.
Map.new('a', 1, 'b', 2).kv # a, 1, b, 2 OR b, 2, a, 1
Map.new('a', 1, 'b', 2).kv # (a 1 b 2)
=head2 method Int
Defined as:
method Int(Map:D:) returns Int:D
Usage:
MAP.Int
Returns the number of pairs stored in the C<Map> (same as C<.elems>).
my $m = Map.new('a' => 2, 'b' => 17);
Expand All @@ -195,10 +173,6 @@ Defined as:
method Numeric(Map:D:) returns Int:D
Usage:
MAP.Numeric
Returns the number of pairs stored in the C<Map> (same as C<.elems>).
my $m = Map.new('a' => 2, 'b' => 17);
Expand All @@ -210,10 +184,6 @@ Defined as:
method Bool(Map:D:) returns Bool:D
Usage:
MAP.Bool
Returns C<True> if the invocant contains at least one key/value pair.
my $m = Map.new('a' => 2, 'b' => 17);
Expand All @@ -225,10 +195,6 @@ Defined as:
method Capture(Map:D:) returns Capture:D
Usage:
MAP.Capture
Returns a L<Capture|/type/Capture> where each key, if any, has been converted
to a named argument with the same value as it had in the original C<Map>.
The returned C<Capture> will not contain any positional arguments.
Expand Down
25 changes: 13 additions & 12 deletions doc/Type/Mu.pod6
Expand Up @@ -4,7 +4,7 @@
=SUBTITLE The root of the Perl 6 type hierarchy.
class Mu {}
class Mu { }
The root of the Perl 6 type hierarchy. For the origin of the name, see
L<https://en.wikipedia.org/wiki/Mu_%28negative%29>. One can also say that
Expand Down Expand Up @@ -110,7 +110,7 @@ C<gist> is the method that L<say> calls implicitly, so C<say $something> and
C<say $something.gist> generally produce the same output.
say Mu.gist; # (Mu)
say Mu.new.gist; # Mu.new()
say Mu.new.gist; # Mu.new
=head2 routine perl
Expand Down Expand Up @@ -259,18 +259,19 @@ Returns an C<Int> representing the memory address of the object.
Returns the attached Pod value. For instance,
=for code
sub cast(Spell $s)
#= Initiate a specified spell normally
#= (do not use for class 7 spells)
{
do-raw-magic($s);
}
say &cast.WHY;
=for code :skip-test
sub cast(Spell $s)
#= Initiate a specified spell normally
#= (do not use for class 7 spells)
{
do-raw-magic($s);
}
say &cast.WHY;
prints
Initiate a specified spell normally (do not use for class 7 spells)
=for code :skip-test
Initiate a specified spell normally (do not use for class 7 spells)
See the L<documentation specification|https://design.perl6.org/S26.html> for
details about attaching Pod to variables, classes, functions, methods, etc.
Expand All @@ -290,7 +291,7 @@ See L<Exporting and Selective Importing Modules|/language/modules#Exporting_and_
for more details.
=head2 method return
method return();
method return()
The method C<return> will stop execution of a subroutine or method, run all
relevant L<phasers|/language/phasers#Block_Phasers> and provide invocant as a
Expand Down

0 comments on commit edbad25

Please sign in to comment.