Skip to content

Commit 2197ec2

Browse files
committed
lastcall is an independent routine ref #3767
1 parent 2c82005 commit 2197ec2

File tree

2 files changed

+43
-47
lines changed

2 files changed

+43
-47
lines changed

doc/Type/Method.pod6

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -62,53 +62,6 @@ friends|/language/functions#Re-dispatching».
6262
B.m( :1a, :2b );
6363
# OUTPUT: «1 named␤2 named␤»
6464
65-
=head1 Methods
66-
67-
=head2 sub lastcall
68-
69-
sub lastcall(--> True)
70-
71-
Truncates the current dispatch chain, which means any calls to
72-
C<nextsame>, C<callsame>, C<nextwith>, and C<callwith> will not
73-
find any of the next candidates. Note that since C<samewith>
74-
restarts the dispatch from the start, it's not affected by the
75-
truncation of current chain with C<lastcall>.
76-
77-
Consider example below. C<foo(6)> uses C<nextsame>
78-
when C<lastcall> hasn't been called, and so it reaches the C<Any>
79-
candidate. C<foo(2)> calls C<nextsame> as well, but since
80-
C<lastcall> was called first, the dispatch chain was truncated and
81-
the C<Any> candidate was not reached. The last call, C<foo(1)>,
82-
calls C<lastcall> too, however, it then uses C<samewith>, which
83-
isn't affected by it, and so the dispatch re-starts from scratch,
84-
hits the C<Int> candidate with the new argument C<6>, and then
85-
proceeds to the C<Any> candidate via C<nextsame> (which
86-
isn't affected by the C<lastcall> that was used before the
87-
C<samewith> was called):
88-
89-
multi foo (Int $_) {
90-
say "Int: $_";
91-
lastcall when *.is-prime;
92-
nextsame when * %% 2;
93-
samewith 6 when * !%% 2;
94-
}
95-
multi foo (Any $x) { say "Any $x" }
96-
97-
foo 6; say '----';
98-
foo 2; say '----';
99-
foo 1;
100-
101-
# OUTPUT:
102-
# Int: 6
103-
# Any 6
104-
# ----
105-
# Int: 2
106-
# ----
107-
# Int: 1
108-
# Int: 6
109-
# Any 6
110-
111-
11265
=end pod
11366

11467
# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6

doc/Type/independent-routines.pod6

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,49 @@ $supply.tap( -> $v { say "Second : $v" }, done => { say "No more" });
13211321
The block passed to the C<done> named argument will be run when C<done> is
13221322
called within the C<supply> block.
13231323
1324+
=head2 sub lastcall
1325+
1326+
sub lastcall(--> True)
1327+
1328+
Truncates the current dispatch chain, which means any calls to
1329+
C<nextsame>, C<callsame>, C<nextwith>, and C<callwith> will not
1330+
find any of the next candidates. Note that since C<samewith>
1331+
restarts the dispatch from the start, it's not affected by the
1332+
truncation of current chain with C<lastcall>.
1333+
1334+
Consider example below. C<foo(6)> uses C<nextsame>
1335+
when C<lastcall> hasn't been called, and so it reaches the C<Any>
1336+
candidate. C<foo(2)> calls C<nextsame> as well, but since
1337+
C<lastcall> was called first, the dispatch chain was truncated and
1338+
the C<Any> candidate was not reached. The last call, C<foo(1)>,
1339+
calls C<lastcall> too, however, it then uses C<samewith>, which
1340+
isn't affected by it, and so the dispatch re-starts from scratch,
1341+
hits the C<Int> candidate with the new argument C<6>, and then
1342+
proceeds to the C<Any> candidate via C<nextsame> (which
1343+
isn't affected by the C<lastcall> that was used before the
1344+
C<samewith> was called):
1345+
1346+
multi foo (Int $_) {
1347+
say "Int: $_";
1348+
lastcall when *.is-prime;
1349+
nextsame when * %% 2;
1350+
samewith 6 when * !%% 2;
1351+
}
1352+
multi foo (Any $x) { say "Any $x" }
1353+
1354+
foo 6; say '----';
1355+
foo 2; say '----';
1356+
foo 1;
1357+
1358+
# OUTPUT:
1359+
# Int: 6
1360+
# Any 6
1361+
# ----
1362+
# Int: 2
1363+
# ----
1364+
# Int: 1
1365+
# Int: 6
1366+
# Any 6
13241367
13251368
=end pod
13261369

0 commit comments

Comments
 (0)