00:36 Manifest left 10:04 lizmat_ joined 10:06 lizmat_ left 10:14 lizmat_ joined 10:15 lizmat_ left 13:03 Chanakan left 14:51 kjp_ left 15:48 Tirifto left
timemelon I'm having a go at this weeks weekly challenge, and I have an expression that works with an explicit block but breaks when replaced with whatever code 15:54
(5, 4)[{$_ ≥ 3 ?? 2 !! 0}] evaluates to 5, which is what I expected 15:55
(5, 4)[* ≥ 3 ?? 2 !! 0] evaluates to Nil, and I'm not sure what the difference is supposed to be 15:56
15:56 Tirifto joined
librasteve dr.doom5771: have you tried rakubrew.org (you can use the build command to compile from source)? 16:01
@timemelon in your first example, you show a block of code in {} curlies in the [] index of the List (5,4) which does a `??!!`` test and returns the result, good 16:03
in the second example, you have removed the curlies {} and used Whatever * --- this syntax is a feature of the .map and .grep methods, but there is no .map in sight so not sure why you would expect this to work just in index [] 16:05
often a bare * in an index context means .elems as in the length of the List, for example [*-1] means the last element in the List, but I guess you can't use * as an argument to a comparison in this situation 16:08
docs.raku.org/language/subscripts#From_the_end 16:11
ah - seems like my guess was a little astray 16:14
actually you CAN use * in a comparison in an index, so this works 16:15
m: say (5, 4)[* ≥ 3 ?? 1 !! 0]
Raku eval 4
librasteve note that (unlike what you want) this is comparing if the length of the List * (ie 2) is ≥ 3 which is False and so it uses 1 as the index 16:17
so you code
m: say (5, 4)[* ≥ 3 ?? 2 !! 0]
Raku eval Nil
librasteve results in index value 2 and that tries to return the non existent 3rd element of your List (indexes start at 0) 16:18
antononcube Can this be simplfied: (5, 4)>>.&infix:<≥>(3).sum 16:19
E.g. without using infix.
And map. 🙂 (I know this works (5, 4).map(*≥3).sum.) 16:20
rcmlz you want the sum of all elements >=3 or the number of elements >= 0 ? 16:26
>=3
antononcube The latter -- to find the number of all elemets greater than 3. I was exeprimenting with cmp and that is why I used .sum instead of .elems. 16:28
rcmlz m: say (1, 2, 5,4)>>.grep(* > 2).elems 17:01
Raku eval 4
rcmlz m: say (1, 2, 5,4).grep(* > 2).elems
Raku eval 2
lizmat m: dd (1, 2, 5,4)>>.grep(* > 2) 17:02
camelia (().Seq, ().Seq, (5,).Seq, (4,).Seq)
lizmat m: dd (1, 2, 5,4).grep(* > 2)
camelia (5, 4).Seq
lizmat an empty Seq is not Empty 17:03
rcmlz m: say (1, 2, 5,4)>>.grep(* > 2).flat.elems
Raku eval 2
rcmlz @lizmat: I was just about to ask why parallel processing is not working in this example. Thanks. 17:04
lizmat n: dd ().Seq.flat 17:05
m: dd ().Seq.flat
camelia ().Seq
lizmat m: dd (().Seq,).flat
camelia ().Seq
rcmlz @antononcube I guess grep+elems is faster than map+sum. 17:07
would be interesting to know what problem size is needed to make >> + flat fastest … 17:11
nahita3882 > which is False and so it uses 1 as the index but when False, it should use 0 as the index because 0 is at the !! part 17:48
similar for Time Melon's original code; it uses 2, hence Nil because out-of-bounds
the problem is * >= 3 ?? 2 !! 0 not being a WhateverCode 17:49
it's evaluated to be 2 because the WhateverCode * >= 3 is truthful
there is this but not sure if simplified: In [20]: sum (5, -4) >>>=>> 3 1 17:50
with Unicode characters for some of those >'s, it may read better 17:51
antononcube Ok, very nice! 17:53
librasteve @nahita3882 - I stand corrected - thanks! So I gather that you cannot use this ternary inside an index. Is this a feature or a bug? 18:20
nahita3882 i think it would have been cooler if it worked but not sure if it is a bug 18:21
maybe the intention with * is that it is used with "quick" stuff and ternary isn't covered 18:22
librasteve m: say (5, 4)[4 ≥ 3 ?? 1 !! 0]
Raku eval 4
librasteve m: say (5, 4)[2 ≥ 3 ?? 1 !! 0]
Raku eval 5
nahita3882 like *.attr, * <infix> sth, *[idx] etc. all works but ternary is too much? idk the details
librasteve m: (5, 4)[*.say] 18:23
Raku eval 2
librasteve (5, 4)[(* ≥ 3).say]
m: (5, 4)[(* ≥ 3).say]
Raku eval False
librasteve looks like ternary is a bug to me
m: say (5, 4)[4 ≥ 3 ?? *-1 !! 0] 18:24
Raku eval 4
librasteve seems to be limited to use of * in the test of a ternary within an [] index 18:25
if you agree I can log as a bug
nahita3882 it doesn't work in [] but it doesn't work outside either 18:26
not working in the sense that it doesn't produce a closure
but instead evaluates to what the truthful part of the ternary gives immediately
because the whatevercode is truthful
like any other sub 18:27
perl In [25]: (* > 3 ?? 2 !! -1).WHAT (Int)
user (like Time Melon and probably us too) expects this to be still WhateverCode
maybe a bug, maybe some technical detail (like ternary shortcircuiting), so it's up to you to file the bug but thanks if you take the time of course 18:29
maybe shortcircuting is the thing: 18:30
perl In [30]: (* >= 2) && 7 7 In [31]: (* >= 2) & 7 WhateverCode.new
perl In [32]: ((* >= 2) & 7).(55) all(True, 7) In [33]: ((* >= 2) & 7).(-55) all(False, 7) 18:31
i.e., with the all-junction, it did produce a closure, which we can call 18:32
with the && logical-and (which shorcircuits), no closure yes direct evaluation
timemelon ohh I see, the whatever code just doesn't include the ternary 20:21
funky, I wonder if there's a list of what is and isn't included anywhere 20:22
docs don't mention ternaries anywhere so idk 20:27
thank you for letting me know why it wasn't working!
21:38 kjp joined 22:01 kjp left, kjp joined 23:32 Chanakan joined 23:35 Chanakan left 23:41 Chanakan joined