Skip to content

Commit 8ca4e59

Browse files
committed
Merge branch 'master' of github.com:perl6/doc
2 parents 7a992e3 + c827a80 commit 8ca4e59

File tree

11 files changed

+110
-10
lines changed

11 files changed

+110
-10
lines changed

CREDITS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
Thanks,
1313

14-
The Rakudo Team
14+
The perl6/doc Team
1515
PS: Yes, this looks remarkably like the Linux CREDITS format
1616
PPS: This file is encoded in UTF-8
1717

lib/Type/Any.pod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Interprets the invocant as a list, and returns that list.
4646
4747
Interprets the invocant as a list, flattens it, and returns that list.
4848
49+
say ((1, 2), (3)).elems; # 2
50+
say ((1, 2), (3)).flat.elems; # 3
51+
4952
=head2 method eager
5053
5154
Interprets the invocant as a list, evaluates it eagerly, and returns that

lib/Type/Mu.pod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,15 @@ Returns an object of type L<ObjAt> which uniquely identifies the object.
137137
Value types override this method which makes sure that two equivalent objects
138138
return the same return value from C<WHICH>.
139139
140+
=head2 trait is export
141+
142+
multi sub trait_mod:<is>(Mu:U \type, :$export!)
143+
144+
Marks a type as being exported, that is, available to external users.
145+
146+
my class SomeClass is export { }
147+
148+
A user of a module or class automatically gets all the symbols imported that
149+
are marked as C<is export>.
150+
140151
=end pod

lib/Type/Parameter.pod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ L<rw|#rw>-parameter which can only bind to variables, never to values.
7070
7171
=head2 method capture
7272
73-
Returns C<True> for parameters that capture the rest of the argument list.
73+
Returns C<True> for parameters that capture the rest of the argument list into
74+
a single object of L<type Capture|/type/Capture>.
7475
75-
sub f(\capture) { }
76+
sub f(|capture) { }
77+
say &f.signature.params[0].capture; # True
7678
7779
Capture parameters do not force any context on the values passed bound
7880
to them, which is why they cannot have sigils.
7981
82+
83+
8084
=head2 method rw
8185
8286
Returns C<True> for C<is rw> parameters.

lib/Type/Routine.pod

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,31 @@ produces
142142
Note that C<return> marks return values as read only; if you need an early
143143
exit from an C<is rw> routine, you have to use C<return-rw> instead.
144144
145+
=head2 trait is export
146+
147+
multi sub trait_mod:<is>(Routine $r, :$export!)
148+
149+
Marks a routine as exported to the rest of the world
150+
151+
=begin code :allow<B>
152+
module Foo {
153+
sub double($x) B<is export> {
154+
2 * $x
155+
}
156+
}
157+
158+
import Foo; # makes sub double available
159+
say double 21; # 42
160+
=end code
161+
162+
From inside another file you'd say C<use Foo;> to load a module and import the
163+
exported functions.
164+
165+
145166
=begin comment
146167
147-
TODO: traits hidden_from_backtrace, export, DEPRECATED
168+
TODO: explain export tags
169+
TODO: traits hidden_from_backtrace, DEPRECATED
148170
149171
=end comment
150172

lib/Type/Signature.pod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ say limit-lines "a \n b \n c", Int; # "a \n b \n c"
146146
For explicitly indicating the normal behaviour, C<:_> can be used, but this is
147147
unnecessary. C<:(Num:_ $)> is the same as C<:(Num $)>.
148148
149-
=head2 Slurpy (A.K.A. Variadic) Parameters
149+
=head2 X<Slurpy (A.K.A. Variadic) Parameters|parameter,*@;parameter,*%>
150150
151151
An array or hash parameter can be marked as I<slurpy> by a leading asterisk,
152152
which means it can bind to an arbitrary amount of arguments (zero or more).
@@ -265,7 +265,7 @@ However, this unpacking of objects as their attributes is only the default
265265
behavior. To make an object get destructured differently, change its
266266
L<C<Capture>> method.
267267
268-
=head2 Capture Parameters
268+
=head2 X<Capture Parameters|parameter,|>
269269
270270
Prefixing a parameter with a vertical bar C<|> makes the parameter a
271271
L<C<Capture>>, using up all the remaining positional and named
@@ -275,7 +275,7 @@ This is often used in L<C<proto> definitions|proto> (like C<proto foo (|) {*}>)
275275
to indicate that the routine's L<C<multi> definitions|multi> can have any
276276
L<type constraints|#Type_Constraints>.
277277
278-
=head2 Parameter Traits and Modifiers
278+
=head2 X<Parameter Traits and Modifiers|trait,is copy;trait,is rw>
279279
280280
By default, parameters are bound to their argument and marked as
281281
read-only. One can change that with traits on the parameter.

lib/Type/WhateverCode.pod

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,53 @@
99
C<WhateverCode> objects are the result of L<Whatever>-currying. See the
1010
L<Whatever> documentation for details.
1111
12+
When you wish to control how a method or function interprets any
13+
I<Whatever stars>, you may use multi dispatch with C<Whatever> and
14+
C<WhateverCode> parameters to do so, as in the following example:
15+
16+
class Cycle {
17+
has $.pos;
18+
has @.vals;
19+
}
20+
21+
multi sub get_val(Cycle $c, Int $idx) {
22+
$c.vals[$idx % $c.vals.elems]
23+
}
24+
25+
# Define what to do with a stand-alone * as the second argument
26+
multi sub get_val(Cycle $c, Whatever $idx) {
27+
get_val($c, $c.pos);
28+
}
29+
30+
# Define what to do with a * in an expression
31+
multi sub get_val(Cycle $c, WhateverCode $idx) {
32+
get_val($c, $idx($c.pos));
33+
}
34+
35+
my Cycle $c .= new(:pos(2),:vals(0..^10));
36+
37+
say get_val($c, 3); # 3
38+
say get_val($c, *); # 2
39+
say get_val($c, *-1); # 1
40+
41+
Since C<WhateverCode> objects are C<Callable> you may use introspection
42+
to create as fancy a behavior as you wish. Continuing the following
43+
example we may add handling for two I<Whatever stars>:
44+
45+
# Define what to do with two * in an expression
46+
multi sub get_val(Cycle $c, WhateverCode $idx where { .arity == 2 }) {
47+
get_val($c, $idx($c.pos, $c.vals.elems));
48+
}
49+
50+
say get_val($c, * + * div 2); # 2 + 10/2 = 7
51+
52+
Note, though, that subexpressions may impose their own I<Whatever star>
53+
rules:
54+
55+
my @a = (0,1,2);
56+
say get_val($c, @a[*-1]) # 2, because the star belongs to the Array class
57+
58+
This can make the ownership of I<Whatever stars> become confusing rather
59+
quickly, so be careful not to overdo it.
60+
1261
=end pod

t/typegraph.t

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ use Test;
33
use lib 'lib';
44
use Perl6::TypeGraph;
55

6+
plan 8;
7+
8+
if $*VM.name eq 'parrot' {
9+
skip_rest 'segfaults on parrot';
10+
exit;
11+
}
12+
613
my $t = Perl6::TypeGraph.new-from-file('type-graph.txt');
714
ok $t, 'Could parse the file';
815
ok $t.types<Array>, 'has type Array';

sync renamed to util/sync

File renamed without changes.

util/sync-build-log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
rsync -az --delete html/build-log/ doc.perl6.org@www.p6c.org:/var/www/doc.perl6.org/build-log/

0 commit comments

Comments
 (0)