Slang::Mosdef
Slang::Mosdef
All the cool kids are using def to declare methods. Now you can, too.
use Slang::Mosdef;
class Foo {
def bar {
say 'I am cool too';
}
method baz {
say 'This is not as much fun';
}
}
You can also use lambda for subs!
my $yo = lambda { say 'oy' };
$yo();
Or 位!
my $twice = 位 ($x) { $x * 2 };
say $twice(0); # still 0
Compute 5 factorial using a Y combinator:
say 位 ( &f ) {
位 ( \n ) {
return f(&f)(n);
}
}(
位 ( &g ) {
位 ( \n ) {
return n==1 ?? 1 !! n * g(&g)(n-1);
}
})(5)