This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
00:06 swaggboi left 00:10 Manifest0 left 00:18 swaggboi joined 03:51 hexology left 03:52 hexology joined 06:08 kjp left 06:11 kjp joined 08:04 Manifest0 joined 11:20 habere-et-disper joined
habere-et-disper Is pi or e evil ? (See recent Numberphile) 11:46
I tried `so 666 | 668 == first * >= 666, [\+] e.comb.grep( *.Int )` but we need more digits for e, so I went with:
m: so 666 | 668 == first * >= 666, [\+] ( { FatRat.new: 1, [*] 1..$++ } ... * ).head( 200 ).sum.comb.grep( *.Int )
camelia WARNINGS for <tmp>:
Useless use of "so " in expression "so 666 | 668 ==" in sink context (line 1)
habere-et-disper Any other approaches / ideas ?
nemokosch markdown ate up a good lot of characters from that code 😦 11:47
habere-et-disper m: so any( 666, 668 ) == first * >= 666, [\+] ( { FatRat.new: 1, [*] 1..$++ } ... * ).head( 200 ).sum.comb.grep( *.Int ) 11:49
camelia WARNINGS for <tmp>:
Useless use of "so " in expression "so any( 666, 668 ) ==" in sink context (line 1)
habere-et-disper REPL is happy. Not sure what md is eating as it seems to display okay here. 11:50
nemokosch could you add backticks for code you post here? 11:51
habere-et-disper With or without "m: " ?
nemokosch postimg.cc/t1j0w1p7
that part doesn't matter for me; if the bot is fine with it then preferably both 11:52
habere-et-disper m: `so 666 | 668 == first * >= 666, [\+] ( { FatRat.new: 1, [*] 1..$++ } ... * ).head( 200 ).sum.comb.grep( *.Int )`
camelia ===SORRY!=== Error while compiling <tmp>
Bogus statement
at <tmp>:1
------> <BOL>⏏`so 666 | 668 == first * >= 666, [\+] (
expecting any of:
prefix
statement list
term
nemokosch heh 11:53
habere-et-disper `m: so 666 | 668 == first * >= 666, [\+] ( { FatRat.new: 1, [*] 1..$++ } ... * ).head( 200 ).sum.comb.grep( *.Int )`
nemokosch but it's readable at least 😄 11:54
Frankly, it would be quite a puzzle to ask somebody "what does this code achieve" 11:55
habere-et-disper I agree. This is simpler but wrong `so 666 | 668 == first * >= 666, [\+] e.comb.grep( *.Int )` 11:57
nemokosch why is the grep(*.Int) necessary? 11:58
habere-et-disper To skip the decimal point ? 11:59
m: [\+] e.comb 12:00
camelia Potential difficulties:
Useless use of [\+] in sink context
at <tmp>:1
------> <BOL>⏏[\+] e.comb
Cannot convert string to number: radix point must be followed by one or more valid digits in '.⏏' (indicated by ⏏)
…
habere-et-disper m: [\\+] e.comb
camelia ===SORRY!=== Error while compiling <tmp>
Prefix + requires an argument, but no valid term found.
Did you mean + to be an opening bracket for a declarator block?
at <tmp>:1
------> [\\+⏏] e.comb
expecting any of:
…
nemokosch not sure if I like the overall "comb and sanitize" approach but I'm pretty sure comb can take a regex, that's already somewhat better
12:37 ab5tract_ joined 13:30 NemokoschKiwi joined 13:36 habere-et-disper left 14:09 NemokoschKiwi left
rcmlz I am playing around with roles. Is it possible to extend build in types? Something like this: role custom-sort { method quicksort(@a) { return @a if @a.elems < 2; my $pivot = @a.pick; my %prt{Order} is default([]) = @a.classify: * cmp $pivot; |samewith(%prt{Less}), |%prt{Same}, |samewith(%prt{More}) } } my @test = 1,2,4,6,3; @test does custom-sort; say @test.quicksort; 17:19
What should be the signature of method quicksort(@a)to make this work? I was looking into IterationBuffer but did not understand it. Any hints?
nemokosch self 17:22
17:53 NemokoschKiwi joined 17:54 NemokoschKiwi is now known as Nemokosch 17:56 Nemokosch left, ab5tract left
rcmlz m: role custom-sort { method quicksort() { return self if self.elems < 2; my $pivot = self.pick; my %prt{Order} is default([]) = self.classify: * cmp $pivot; |samewith(%prt{Less}), |%prt{Same}, |samewith(%prt{More}) } } my @test = 1,2,4,6,3; @test does custom-sort; say @test.quicksort; 18:05
Raku eval (1 2 3 4 6)
rcmlz Thank you.
nemokosch well, you did the heavy lifting by getting the most out of a semi-joke answer 😄 18:06
rcmlz m: role custom-sort { method quicksort() { return self if self.elems < 2; my $pivot = self.pick; my %prt{Order} is default([]) = self.classify: * cmp $pivot; |samewith(%prt{Less}), |%prt{Same}, |samewith(%prt{More}) } method quicksort-parallel(:$batch) { return self if self.elems < 2; my $pivot = self.pick; my %prt{Order} is default([]) = 18:14
self.classify( * cmp $pivot ); my $less = %prt{Less}.elems >= $batch ?? start { samewith(%prt{Less}, $batch) } !! samewith(%prt{Less}, $batch); my $more = samewith(%prt{More}, $batch); await $less andthen $less = $less.result if $less ~~ Promise; |$less, |%prt{Same}, |$more; } } my @test = 1,2,4,6,3; @test does custom-sort; say
@test.quicksort-parallel(batch => 1024);
Raku eval Exit code: 1 Too many positionals passed; expected 1 argument but got 2 in method quicksort-parallel at main.raku line 8 in method quicksort-parallel at main.raku line 14 in block <unit> at main.raku line 24
rcmlz I do not fully understand it - when putting another $self into it is also is not working. 18:15
nemokosch it's the zeroeth argument; the one followed by a colon rather than a comma 18:20
not sure you can do it with samewith though 18:21
%prt{Less} probably doesn't even have this method 18:23
why do you want a method instead of a global sub? The suggestion may depend on the answer 18:24
rcmlz I thought it is easier for testing. But with recursion + parameter it is defenitely not. 18:36
Maybe if it is done in-place, but with my copy-approach I realize I have to attach the role inside again ... 18:37
thank you for helping me understanding this. 18:38
nemokosch it's easy to fake a global function as a method, the .& syntax is nice
it's much harder the other way around
rcmlz I can confirm ;-) 18:40
librasteve rcmlz: try with a colon before the $batch param - :$batch ... that makes the pair batch => $batch 18:44
my $less = %prt{Less}.elems >= $batch 13 ?? start { samewith(%prt{Less}, :$batch) } 14 !! samewith(%prt{Less}, :$batch); 15 my $more = samewith(%prt{More}, :$batch);
haviong said this, I don't think that you are using samewith right ... since this will call again the same method like this "self.quicksort-parallel(XXX, :$batch); and therefore should be used with multi method since this idea is to redispatch the method a different route with the new params... maybe I am missing something, but I do not think that the XXX magically becomes the invocant self object 18:53
23:02 habere-et-disper joined
habere-et-disper Is it expected that `snip` will support chained comparisons ? 23:05
m: say snip ( * < 6, * <= 8 ), 1..10;
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
snip used at line 1. Did you mean 'slip', 'skip'?
habere-et-disper m: use use v6.e.PREVIEW; say snip ( * < 6, * <= 8 ), 1..10;
camelia ===SORRY!=== Error while compiling <tmp>
Could not find use in:
/home/camelia/.raku
/home/camelia/rakudo-m-inst-2/share/perl6/site
/home/camelia/rakudo-m-inst-2/share/perl6/vendor
/home/camelia/rakudo-m-inst-2/share/per…
habere-et-disper m: use v6.e.PREVIEW; say snip ( * < 6, * <= 8 ), 1..10;
camelia ((1 2 3 4 5) (6 7 8) (9 10))
habere-et-disper m: use v6.e.PREVIEW; say snip ( 6 < * <= 8 ), 1..10; 23:06
camelia ((1) (2 3 4 5 6 7 8 9 10))
nemokosch will or will not? 23:09
normally, 6 < * <= 8 should codegen to a working function that checks what you think it should
23:25 habere-et-disper left