00:24 arkiuat left 00:53 arkiuat joined 00:58 arkiuat left 01:08 hulk joined, kylese left 01:28 arkiuat joined 01:32 arkiuat left 01:55 arkiuat joined 02:15 hulk left, kylese joined 02:22 nort joined 02:57 Aedil left 03:03 stanrifkin_ joined 03:06 stanrifkin left 03:27 arkiuat left 04:10 elcaro left 04:20 Aedil joined 04:21 maylay left 04:50 kylese left, kylese joined
disbot <simon_sibl> is it possible to have an optional variable argument in a subroutine that is also mutable ? 05:38
<simon_sibl> sub schedule(@str_jobs, $time is rw = 0) {*} doest work..
Voldenet no idea what you precisely mean, but maybe `is copy` would work 05:40
probably not 05:41
disbot <simon_sibl> oh is copy work 05:45
<simon_sibl> thanks !
Voldenet but then, of course, it doesn't alter the value you pass in 05:46
m: sub set-value($n is rw) { $n = 42; }; my $x = 2; set-value($x); say $x
evalable6 42
Voldenet if you wanted "optional output" in such case, I know that multi would work 05:47
disbot <simon_sibl> oh it doesnt have to alter the value I pass in, at least not for now
Voldenet m: multi sub set-value($n is rw) { say "rw"; $n = 42; }; multi sub set-value { say "optional multi"; samewith($ = 2); }; my $x = 2; set-value($x); set-value(); say $x 05:48
evalable6 rw
optional multi
rw
42
06:01 derpydoo joined
disbot <simon_sibl> 🙏 had to lookup samewith xD 06:07
Voldenet I pondered and there is a way to do it 06:18
06:19 Aedil left
Voldenet m: sub schedule(@str_jobs, $time is raw = ($ = 0)) { $time = 42 }; my $n = 1; schedule([], $n); schedule([]); say $n 06:19
evalable6 42
Voldenet it's a lot cleaner
m: sub schedule(@str_jobs, $time is raw = (my $x = 0)) { say $x.defined; $time = 42 }; my $n = 1; schedule([], $n); schedule([]); say $n # if you need to know whether default value was used or not 06:21
evalable6 False
True
42
disbot <simon_sibl> thank you so much 🙏
<simon_sibl> I try to sort the jobs before passing them to the sub with basically @jobs.map(...).sort-jobs 06:22
<simon_sibl> but I get No such method 'sort-jobs' for invocant of type 'Seq'
<simon_sibl> its just a sub sort-jobs(@jobs) {@jobs.sort(...)}
Voldenet @jobs.map(…).&sort-jobs 06:23
`.thing` syntax calls the method of the lvalue
well not lvalue, but the thing on the left 06:24
disbot <simon_sibl> isnt the thing on the left the result of the map ? 06:25
Voldenet yes, but if @jobs is a regular array or list and map is the default method, map returns sequence 06:27
disbot <simon_sibl> I get a Malformed postfix call if I use .&sort-jobs 🥹
06:27 derpydoo left
disbot <simon_sibl> oh when all is on one line it works 06:28
<simon_sibl> I thought I could add newline before the . calls
Voldenet m: sub sort-jobs(@p) { @p.sort }; my @a = 1..5; @a.map(20 - *).&sort-jobs.say
evalable6 (15 16 17 18 19)
Voldenet yeah it's some old design decision that it must be on one line :\ 06:29
iirc
06:35 jjido joined 06:49 wayland joined 07:02 disbot7 joined, disbot left 07:03 disbot7 is now known as disbot
disbot <simon_sibl> I dont get why this doesnt work 07:05
<simon_sibl> sub sort-jobs(@jobs) { @jobs.sort: { $^a<priority> <= $^b<priority>, $^a<submit> <=> $^b<submit> } }, when I just do sort: {-.priority, .submit} it works but less flexlible
<simon_sibl> > This type cannot unbox to a native integer: P6opaque, List 07:10
07:10 jjido left 07:17 jjido joined
disbot <simon_sibl> forces me to do .sort().sort() xD 07:23
Voldenet m: enum prio <low med high>; sub sort-jobs(@jobs) { @jobs.sort({ -.<prio>, .<submit> }) }; my @jobs = do for ^20 { %(prio => prio.roll, submit => (^10).roll) }; .say for @jobs.&sort-jobs 07:26
evalable6 {prio => high, submit => 0}
{prio => high, subm…
Voldenet, Full output: gist.github.com/f4c29e88e284df05fa...7f5155115b
Voldenet yeah it works ofc
but in $^a $^b form you're supposed to return -1 0 or 1 07:30
not list
Order::Same, Order::Less or Order::More even ;\ 07:33
07:36 Sgeo left
wayland simon_sibl: It's specifically complaining that the return value from the sort block is of the wrong type. 07:36
disbot <simon_sibl> but why in one way it accepts a list and in another way it doesnt ? 07:37
07:38 jjido left
Voldenet because in one case it accepts one argument and extracts list of values to match 07:39
and in second it accepts two arguments and produces comparison results
you can do something like this if you really need second form 07:43
m: enum prio <low med high>; sub sort-jobs(@jobs) { @jobs.sort({ $^b<prio> <=> $^a<prio> || $^a<submit> <=> $^b<submit> }) }; my @jobs = do for ^20 { %(prio => prio.roll, submit => (^10).roll) }; .say for @jobs.&sort-jobs
evalable6 {prio => high, submit => 0}
{prio => high, subm…
Voldenet, Full output: gist.github.com/e55d72c8c7b6c55d1c...dfaf3f5473
disbot <simon_sibl> aaah I havent thought of that, thank you ! 07:46
wayland Voldenet: Do you know how sort decides which form it has? Links to doco appreciated :) 07:47
Voldenet one/two arguments being expected according to docs: docs.raku.org/type/List#routine_sort 07:52
in practice it does .arity on the comparing routine
github.com/rakudo/rakudo/blob/main...umod#L1400 07:53
Oh and, the form that returns Order is going to be a lot faster at the moment (rakuast could significantly speed it up by rewriting one form to the other) 07:59
wayland Nice! Thanks :) 08:00
Voldenet I'm not sure if it that has to be the case though, in theory it's possible to do recursive sort on every field in list 08:02
disbot <simon_sibl> please critic my code: termbin.com/408w, especially if its to discover shorter and simpler way to do this the "raku" way, its a basic scheduler, it calculates the average wait time for each priority level of jobs 08:05
08:05 lichtkind joined 08:06 lizmat_ left 08:07 lizmat joined
Voldenet this sort is not going to work, it has to return not `1/0` but also `-1` 08:08
you have to use <=>
and .sort(…).sort(…) is not going to work well either 08:13
it might work due to sort stability, but I'm not sure if it's guaranteed in practice 08:19
08:34 maylay joined
Voldenet heh, I looked at the code again – in fact, the `grep(.<submit>)` has probably no point 08:38
because it's a very silly sorting method, but you end up with sorted jobs anyway
disbot <simon_sibl> its because the sort is first by priority but yeah, if you have a better shorter way, please let me know xD 08:56
<simon_sibl> It’s a grep < and == and > It’s to make the 3 list of priority Or I sent the wrong code ? Let me check 09:07
<simon_sibl> Yeah yeah the grep is a bit silly but it’s to make the 3 lists
09:30 apac joined 09:49 tejr left 10:09 elcaro joined 10:27 jjido joined, apac left 10:32 jjido left 10:35 tejr joined 11:33 camelia joined 11:41 apac joined
disbot <simon_sibl> alright: termbin.com/1w6f 11:43
<simon_sibl> better right ?
<simon_sibl> (shorter and maybe a bit less readable) termbin.com/4n75 11:57
Voldenet heh I feel like the last code is actually more readable 12:05
12:10 jjido joined, jjido left
disbot <jubilatious1_98524> @simon_sibl typo? $^a<priority> <= $^b<priority> 12:15
Voldenet actually, after reading and understanding what that sort actually does, you need to find the minimum 12:17
not sort the list
12:20 nort left
Voldenet > @jobs.min(:p, { +($^a<submit> > $time), -$^a<priority>, $^a<submit> }) 12:20
something like this perhaps
or 12:21
> @jobs.min(:p, { +($^a<submit> > $time), -$^a<priority>, $^a<submit> }).head # we don't care which pending item with the same priority 12:22
it's bound to be orders of magnitude faster, because it would just go through the list once 12:23
afterwards, you would need to either extract the item from list or set it to Any 12:26
m: enum prio <low med high>; my @jobs = do for ^10 { %(priority => prio.roll, submit => (^10).roll) }; my $time = 3; while $_ = @jobs.min(:p, { +(.<submit> > $time), -.<priority>, .<submit> }).head { say "processing {.value.gist}"; @jobs[.key] = Any }; 12:28
camelia processing {priority => high, submit => 3}
processing {priority => med, submit => 2}
processing {priority => med, submit => 2}
processing {priority => low, submit => 3}
processing {priority => high, submit => 4}
processing {priority => med, …
disbot <simon_sibl> for the last link ? 12:34
<simon_sibl> oh wow Voldenet, I need to check that min function 13:04
<simon_sibl> not sure how I would combine that with the shift, but the min should be faster than the sort for sure 13:07
<simon_sibl> pretty happy with the last one, pretty short and clear, the one who made the challenge and solved it with Python had it in ~70 lignes 13:12
<simon_sibl> for the first argument I am not sure to understand +($^a<submit> > $time) 13:16
<simon_sibl> why not keeping the <=>, because with > we wont have the difference between the late one and the on time jobs right ? 13:20
<jubilatious1_98524> @simon_sibl When sorting I'd use <=> or leg or cmp with $^a $^b. 13:40
<simon_sibl> when going while @jobs.min(:p, { $^a<submit> <=> $time, -$^a<priority>, $^a<submit> }) -> $i, $j { even with .head and .flat and <> it doesnt want to split the item in two, I thought <> could be used to decontainerize 13:45
<simon_sibl> I tried with <=> and it works with min 🙏
<simon_sibl> but so far, this do it pretty well and faster thanks to the usage of min instead of sort 🙏 (thank you again Voldenet) 13:50
<simon_sibl> termbin.com/afnz
<nahita3882> you are passing :p to &min, so it returns a Sequence of Pairs. To match this on the destructuring side, you can do, e.g., -> (:$key, :$value) 14:10
<nahita3882> if you want names other than "key" and "value", you can use the aliasing as -> (:key($i), :value($j)) 14:11
<nahita3882> lastly, when you do -> $i, $j (i.e., without the parens), this will make the loop request 2 things from the iterated thing at a time, and assign first to $i, second to $j 14:12
<nahita3882> as such, for example, it would fail if the iterable doesn't have even number of elements (can workaround that by -> $i, $j? but that's a digression) 14:13
<nahita3882> so with parens, I'd like to think of it as "okay give me 1 thing, and I want it destructured as what's in the parens" 14:14
<nahita3882> ($i, $j) wouldn't work though, since Pair is not Iterable to give its 2 components like that unlike a List 14:15
<simon_sibl> That makes a lot more sense, thank you Still have a lot to learn about those list xD still need to review how >> works also 14:23
14:24 Sgeo joined
disbot <simon_sibl> Destruction seems very nice, also need to learn more about it, I think I got it for the sub side but here I couldn’t see the key/value when doing say on it so I didn’t think about trying 14:24
14:24 apac left 14:27 melezhik joined 14:36 perryprog left, perryprog joined 15:02 topnep joined
Voldenet simon_sibl: re `+(.<submit> > $time)`: this translates to `is the job overdue already` - overdue jobs should get `0` (so their first "digit" in min is 0), non-overdue ones get `1` 15:27
but if you replace the cmp with `<=>`, overdue jobs will get -1, jobs that should start now will get `0` and non-overdue jobs will get 1, it changes the algorithm a bit I guess 15:31
16:48 GreaseMonkey left, greaser|q joined 16:57 melezhik left 17:31 bdju left 18:05 bdju joined 18:15 librasteve_ joined 18:29 tgt joined
disbot <librasteve> ~~ 18:30
18:31 tgt left 18:48 topnep left 18:49 topnep joined 18:55 nort joined 19:01 lichtkind left 20:59 andinus left, andinus joined 21:22 Guest66 joined 21:27 Guest66 left 21:39 bdju left 21:48 bdju joined 22:17 greaser|q left, greaser|q joined, greaser|q is now known as GreaseMonkey 22:30 Altreus left, Altreus joined 23:06 wayland left 23:23 nort left 23:30 stanrifkin_ left 23:31 librasteve_ left