This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub r2s (Rat $rat) { | |
my $s = $rat < 0 ?? '-' !! ''; | |
my $r = $rat.abs; | |
my $i = $r.floor; | |
$r -= $i; | |
$s ~= $i; | |
if $r { | |
$s ~= '.'; | |
while $r and $s.chars < 41 { | |
$r *= 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub r2s (Rat $rat, $base = 10) { | |
my $s = $rat < 0 ?? '-' !! ''; | |
my $r = $rat.abs; | |
my $i = $r.floor; | |
$r -= $i; | |
$s ~= $i.base($base); | |
if $r { | |
my $want = $r.denominator < $base**6 ?? 6 !! $r.denominator.log($base).ceiling + 1; | |
my @f; | |
while $r and @f < $want { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub r2s (Rat $rat) { | |
my $s = $rat < 0 ?? '-' !! ''; | |
my $r = $rat.abs; | |
my $i = $r.floor; | |
$r -= $i; | |
$s ~= $i; | |
if $r { | |
$s ~= '.'; | |
my $place = 0; | |
my %seen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub r2s (Rat $rat) { | |
my $s = $rat < 0 ?? '-' !! ''; | |
my $r = $rat.abs; | |
my $i = $r.floor; | |
$r -= $i; | |
$s ~= $i; | |
if $r { | |
$s ~= '.'; | |
my $place = 0; | |
my %seen; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub fibo ($n) { | |
constant @starters = 1,1,2,4 ... *; | |
nacci @starters[^$n]; | |
} | |
sub nacci (*@starter) { | |
my &fun = eval join '+', '*' xx @starter; | |
@starter, &fun ... *; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum RedBlack <R B>; | |
multi balance(B,[R,[R,$a,$x,$b],$y,$c],$z,$d) { [R,[B,$a,$x,$b],$y,[B,$c,$z,$d]] } | |
multi balance(B,[R,$a,$x,[R,$b,$y,$c]],$z,$d) { [R,[B,$a,$x,$b],$y,[B,$c,$z,$d]] } | |
multi balance(B,$a,$x,[R,[R,$b,$y,$c],$z,$d]) { [R,[B,$a,$x,$b],$y,[B,$c,$z,$d]] } | |
multi balance(B,$a,$x,[R,$b,$y,[R,$c,$z,$d]]) { [R,[B,$a,$x,$b],$y,[B,$c,$z,$d]] } | |
multi balance($col, $a, $x, $b) { [$col, $a, $x, $b] } | |
multi ins( $x, @s [$col, $a, $y, $b] ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub partition(@mask is copy) { | |
my $last = [+] @mask or return [[] xx @mask]; | |
sort gather for @mask.kv -> $k,$v { | |
next unless $v; | |
temp @mask[$k] -= 1; | |
for partition @mask { .take.[$k].push($last) } | |
} | |
} | |
.perl.say for partition [2,0,2]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Unhandled exception: System.InvalidCastException: Cannot cast from source type to destination type. | |
at Niecza.CLRBackend.DowncallReceiver.new_unit (System.Object[] args) [0x00000] in <filename unknown>:0 | |
at Niecza.CLRBackend.DowncallReceiver.Call (System.Object[] args) [0x00000] in <filename unknown>:0 | |
at Niecza.CLRBackend.DowncallReceiver.get_Item (System.Object i) [0x00000] in <filename unknown>:0 | |
at /home/larry/perl6/niecza/src/NieczaFrontendSTD.pm6 line 273 (ANON @ 3) | |
at <unknown> line 0 (ExitRunloop @ 0) | |
at /home/larry/perl6/niecza/src/NieczaFrontendSTD.pm6 line 274 (NieczaFrontendSTD.parse @ 61) | |
at /home/larry/perl6/niecza/src/NieczaCompiler.pm6 line 34 (NieczaCompiler.compile @ 18) | |
at /home/larry/perl6/niecza/src/NieczaCompiler.pm6 line 65 (NieczaCompiler.compile_string @ 5) | |
at /home/larry/perl6/niecza/src/niecza line 165 (ANON @ 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use NativeCall; | |
sub fork() returns Int is native { ... } | |
if fork() -> $pid { | |
print "I am the proud parent of $pid.\n"; | |
} | |
else { | |
print "I am $*PID. Have you seen my mommy?\n"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
role DLL_Element[::T] { | |
has ::?CLASS $.prev is rw; | |
has ::?CLASS $.next is rw; | |
has T $.payload handles *; | |
method pre-insert(T $payload) { | |
die "Can't insert before beginning" unless $!prev; | |
my $elem = ::?CLASS.new(:$payload); | |
$!prev.next = $elem; | |
$elem.prev = $!prev; |