stevied where can I find a good example of a module that has both a functional and OO interface? 01:46
03:13 discord-raku-bot left, discord-raku-bot joined 03:17 discord-raku-bot left, discord-raku-bot joined 05:35 discord-raku-bot left 05:38 RakuIRCLogger left 05:39 stevied left 05:40 discord-raku-bot joined, TempIRCLogger joined 08:04 dakkar joined 10:24 frost joined 10:35 frost left 10:53 frost joined 11:55 frost left 12:19 frost joined 12:26 frost left 12:42 frost joined 13:13 dakkar left 13:14 dakkar joined
Hi, the doc at suggests doing this to prevent getting an error: `run('false').so; # OK. Evaluates Proc in Bool context; no sinking` 14:52
14:52 frost left
but this does not accord with my experience. I'm still getting an error on my mac 14:53
14:55 discord-raku-bot left, discord-raku-bot joined
MasterDuke on linux, without the `.so` i get `The spawned command 'false' exited unsuccessfully (exit code: 1, signal: 0) in block <unit> at -e line 1`. with `.so` i don't get any error 14:56
stevied i'm running this in a test. let me paste my output 14:57
MasterDuke looks like you're doing `run(...).so.exitcode`, or something like that 14:58
stevied i guess it's just the test summary report showing the errors
ah, maybe that's it 14:59
forgot to change the line below
here's my test file: 15:00
how do I fix that?
Nemokosch m: my $squares = (0..*).map: * ** 2; dd (1..*).map({ $squares.head: $_ }); 15:03
I wonder of there is an easier/ better way to do this
... or a working way 😆
stevied i guess I can just catch the error
MasterDuke as it is you're definitely calling .exitcode on the result of .so, which is a Bool 15:04
Nemokosch It's not nice of head that it mutates the iterator in place 15:05
stevied right. but how do I run that command and test the exitcode?
without a bunch of errors? 15:06
MasterDuke you could just check the result of the .so. should be False if there was an error and True if not 15:07
stevied Yeah, just figured that out. so run('blah') 15:09
MasterDuke you don't even need the .exitcode then, but yeah, should be the same
stevied i really don't understand why that's considered to be a "SUNK" context if I'm assigning the right hand side to a value 15:11
MasterDuke i guess because you're not "using" it 15:12
but for me, `my $a = run("false")` doesn't give any error 15:13
stevied huh
let me try outside of a test
yeah, no error for me either 15:15
i wonder why that would be
must have something to do with the guts of test harness. beyond my paygrade. but seems like a bug 15:17
15:34 RakuIRCLogger left
Nemokosch m: dd (1..*).map({ (0..*).map(* ** 2).head: $_ }); 15:36
is there a better way to take longer and longer parts of a sequence? 15:38
and, asking for the eventual purpose: is there a simple way to Descartes-multiply infinite sequences without going to straight to infinity on one side? 15:39
or at least do this for the same sequence on both sides 15:40
as if you were to generate all rational numbers or something
15:49 TempIRCLogger joined
guifa I'm not sure if .map is eager, but if they were lazy sequences it shouldn't cause a problem 15:56
15:57 guifa left
Nemokosch oh, this is what _produce_ is for 16:07
m: dd ^* ** 2).produce(&[,]).head(10);
precedence be like
dd (^Inf).map(* ** 2).produce(&[,]).head(10);
m: dd (^Inf).map(* ** 2).produce(&[,]).head(10); 16:09
16:11 discord-raku-bot left 16:12 discord-raku-bot joined
m: dd [\,] (1..^Inf) andthen .map({ .[*-1] X @$_ }) andthen .head(10) 16:20
almoost xd 16:21
m: [,] (1..^Inf) andthen .map({ .[*-1] X @$_ }) andthen .head(10) andthen .&dd
bruh moment
oh, it ate the backslash 16:22
m: [\\,] (1..^Inf) andthen .map({ .[*-1] X @$_ }) andthen .head(10) andthen .&dd
then 16:23
m: [\,] (1..^Inf) andthen .map({ .[*-1] X @$_ }) andthen .head(10) andthen .&dd
should have worked
no timeout
now THIS is cool
m: [\,] (1..^Inf) andthen{ .[*-1] X .[0..^*-1] andthen .Slip}).head(10) andthen .say 16:29
I think you are starting to get the idea...
16:42 dakkar left
Anton Antonov @Nemokosch#9980 I am getting errors with the last code you posted. Is that (un-)expected? 17:47
Nemokosch no, it's discord being discord, haha 17:48
it ate some characters
it turned *-1 to -1
and \\, to ,
btw it seems to me that no matter how clever this looks, it's actually too slow 17:50
Anton Antonov Ok, good to know -- is running for more than 20 sec on my machine... 17:51
Nemokosch that's probably because of some syntax problem though 17:52
the example I posted was still okay but when I tried to use it for the actual problem, it was too slow
or we will see, I'm rewriting it with simple nested loops
17:54 [Coke] left 17:58 [Coke] joined
Anton Antonov Ok 17:58
Nemokosch No... it's slow either way... 18:03
ngl I'm starting to not like this certain "weekly challenge"
it does work but it takes almost a minute to run 18:13
the "clever nesting" starts to blow up around 500 18:17
the other doesn't really blow up, after all, it's a nothing special O(n^2) thing
something shocks me though 18:24
18:35 SmokeMachine left, lizmat left, Manifest0 left, gfldex left, thowe left, sivoais left, mjgardner left, samebchase left, TempIRCLogger left, tbrowder left, Util_ left, [Coke] left, discord-raku-bot left, qorg11 left, codesections left 18:39 SmokeMachine joined, [Coke] joined, TempIRCLogger joined, lizmat joined, qorg11 joined, Manifest0 joined, codesections joined, sivoais joined, thowe joined, gfldex joined, mjgardner joined, samebchase joined, Util_ joined, tbrowder joined 18:40 discord-raku-bot joined
like I literally made the Python based on the Raku 18:40
and there is a solid magnitude difference
gfldex @Nemokosch#9980 Profiler reports one nasty:bind_cap_to_sig 19:13
gen/moar/BOOTSTRAP/v6c.nqp:1016 2345715
35.73% (17093.77ms)
5.43% (2595.95ms)
Nemokosch what does that mean? 19:14
gfldex The following is the main culprit: my ($bigger-p, $smaller-p) := P($bigger), P($smaller); 19:15
That is a known problem. The compiler wont optimise that one.
Nemokosch my ($bigger-p, $smaller-p) = P($bigger), P($smaller); 19:16
is still slow like hell
gfldex just splitting that one makes it 3x faster: 19:17
my $bigger-p = P($bigger);
my $smaller-p = P($smaller);
The rest will be Int vs float.
lakmatiol I rewrote the raku to Ints only using `div` and it's still 10s vs 1s 19:19
Nemokosch ^this
is it sqrt then? or what?
lakmatiol oh, 4s now
Nemokosch anyway, what is to optimize about my ($bigger-p, $smaller-p) := P($bigger), P($smaller);
in the first place?
lakmatiol well, it shouldn't construct, then deconstruct, two objects. Even python optimizes it into 2 assignments 19:20
Nemokosch indeed it shouldn't xD 19:21
lakmatiol I remember having some issues with raku arithmetic performance before 19:23
[Coke] Is there a gist somewhere with the code? 19:24
the formatting from discord to IRC makes me think it's incomplete.
Nemokosch even if performance doesn't have to be the biggest priority, I don't think losing to Python by a magnitude is acceptable... 19:25
Nahita Curious: you can `last` the outer loop right away in Raku right, i.e., without needing a `$found`? 19:27
gfldex [Coke]:
Nemokosch yes, you can 19:29
I just removed it because I found it suspicious
but it wasn't a problem
I dumbified the loop as well
from for 1..^Inf -> $bigger
But apparently the more basic things were more problematic 19:31
and sadly those are harder to help
like can I do float arithmetics and still get a good enough result? 19:32
gfldex m:```
#! /usr/bin/env -S raku --profile=pentathing-profile.html
sub is-pentagon($c is raw) { (1+sqrt(1+24*$c))%%6 }
sub P($n is raw) { $n*(3*$n-1) div 2 }
my int $bigger = 1;
BAIL: loop {
for 1..^$bigger -> $smaller is raw {
my $bigger-p := P($bigger);
my $smaller-p := P($smaller);
if is-pentagon($bigger-p + $smaller-p) && is-pentagon($bigger-p - $smaller-p) {
say "$bigger $smaller";
last BAIL;
That's how far I got, without a rewrite. 19:33
Nemokosch What about using the for 1..^Inf loop?
[Coke] Guessing you'd do better with more explicit types. 19:34
Nemokosch This is definitely a big deal though 19:35
gfldex Well, I'm at a point where I would need to understand the algorithm but can't, because I'm really hungry. :)
Nemokosch and it seems to me that it's known
gfldex Pizza Time! \o/ 19:36
Nemokosch 4 vs 1 is still big but let's say it's not a show-stopper
30 vs 1 is a show-stopper
[Coke] 19:45
gfldex m:``` 19:46
sub is-pentagon(Int $c --> Bool) { (1+sqrt(1+24*$c))%%6 }
sub P(int $n --> Int) { ($n*(3*$n-1)/2).Int }
my int $bigger = 1;
BAIL: loop {
for 1..^$bigger -> \smaller {
my Int $bigger-p = P($bigger);
my Int $smaller-p = P(smaller);
if is-pentagon($bigger-p + $smaller-p) && is-pentagon($bigger-p - $smaller-p) {
say $bigger, smaller;
last BAIL;
Didn't help. :(
Nemokosch rippers
[Coke] the original version you had ran in 9+ seconds here, the version at my gist (faster+1) is running in 7.3s 19:47
m: say 7.3/9.4 19:48
camelia 0.776596
lizmat runs in 4.35 secs for me
[Coke] (my version has mostly "int" vs. "Int" which may help; there's one Int left that is doing an explicit cast on the result of P(), not sure if we can eliminate that... oh, yah, if we do it with int math instead of Rat math. 19:49
lizmat -> int $smaller also helps a bit for me 19:54
also: P and is-pentagon are getting inlined pretty quickly, so no real point inlining them menually 19:57
Nemokosch is there a point in caching P? 19:58
20:01 discord-raku-bot left, discord-raku-bot joined
gfldex m:``` 20:07
use v6.*;
sub is-pentagon($c is raw) { (1+sqrt(1+24*$c))%%6 }
sub P($n is raw) { $n*(3*$n-1) div 2 }
my atomicint $bail = 0;
(^∞).hyper(:batch(64)).map( -> \b {
last if $bail;
for (1..^b) -> \s {
my \bp = P(b);
my \sp = P(s);
if is-pentagon(bp + sp) && is-pentagon(bp - sp) {
say [b, s];
say now - BEGIN now;
That runs with 1.277238915s on my box but does not terminate.
And I think it should terminate indeed.
Nemokosch pff 20:09
The speed gain isn't that fast because we stop way way before we hit ^∞ .
lizmat gfldex: there's no guarantee you'll see the first bail? 20:13
hmmm... I guess with hyper you would :-)
stevied is there a way to generate numbered lists with pod? 23:00
gfldex That's up to the renderer. 23:48