-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRecursion.rakumod
More file actions
21 lines (18 loc) · 907 Bytes
/
Recursion.rakumod
File metadata and controls
21 lines (18 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
unit module Self::Recursion;
class X::_::Unsupported is Exception is export {
method message { "Sorry, multis with no proto (or with an onlystar proto) don't currently\n"
~"work with \&_. Either use \&?ROUTINE instead, or add a proto with " ~ '{{*}}' }
}
#| Proxy to store the &calling-fn the first time we get it (to avoid walking the callframe each time)
sub ROUTINE is rw {
my &calling-fn;
Proxy.new: FETCH => method () { &calling-fn },
STORE => method (&new is raw){ &calling-fn = &new }}
my $fn := ROUTINE;
our proto term:<&_>(|) is export {*}
multi term:<&_> {
if callframe(1).code.?multi.not { $fn = callframe(1).code }
elsif callframe(1).code.name eq callframe(2).code.name { $fn = callframe(2).code }
else { die X::_::Unsupported.new }
$fn
};