04:40 zacts joined 05:20 zacts left 05:29 zacts joined 05:32 zacts left 09:34 qorg11 left 09:36 qorg11 joined 10:28 wingfold joined 11:45 MasterDuke left 11:51 MasterDuke joined 13:08 jgaz joined 13:11 TempIRCLogger joined
stevied stackoverflow.com/questions/717020...wildly-off 13:20
anyone got any ideas on this?
Anton Antonov How can I get machine epsilon or ULP in Raku? 14:28
14:53 jgaz left
venus007e Is there a filter function in Raku? 15:07
stevied grep: docs.raku.org/type/List#routine_grep 15:08
15:10 discord-raku-bot left 15:11 discord-raku-bot joined
venus007e How can i use grep to filter out everything from a string, except numbers? I tried ``$string.grep: {"1234567890".contains($_)}``, but that doesnt seem to work 15:32
lizmat in Raku a string is an atomic entity, and you can only use .grep sensibly on lists 15:34
m: say "abc123ghi".subst(/ <[0123456789]> /, :g ) 15:35
camelia abcghi
lizmat is probably more what you want ?
if the number can be any number, then:
m: say "abc123ghi".subst(/ \d /, :g )
camelia abcghi
Anton Antonov Well, Liz beat me to it, but I also worked on answer... 15:36
Well, Liz beat me to it, but I also worked on a answer... 15:38
gfldex @stevied#8273 Inconsistent timings can result from (delayed) JITing or the GC kicking in. 15:49
stevied well all that's above my ability to understand. but isn't timing wall clock seconds as easy as nothing the time something started and when it ended based on the the machine's clock? why would that not be accurate? 15:55
gfldex That part is accurate. But you cant execute a loop while it is being JITed, so that thread has to pause for a while. 15:59
stevied no idea what that means, sorry. so anyway, how do I benchmark code? 16:04
is the Bench module even a useful tool? 16:05
gfldex Benchmark the whole bunch 10x and throw the first 2 rounds away. 16:07
stevied so run the timethese method 10 different times? 16:16
is there something I can read that can at least get me some basic clue as to how a script is complied and run? I'm totally lost. 16:18
venus007e How can i use grep to filter out everything from a string, except numbers? I tried ``$string.grep: {"1234567890".contains($_)}``, but that doesnt seem to work 16:30
stevied a substitution would probably be easier to write: `$string ~~ s:g/\d+//;` 16:34
venus007e wtf 16:35
stevied that strips out numbers
if you wan to keep numbers, you'd do:
`$string ~~ s:g/<-[\d+]>//;` 16:36
that's a regular expression
venus007e what in that does what?
stevied have you used regular expressions before?
venus007e nope
stevied great tool. just about every language has them these days 16:37
at least ones I'm familiar with
see regex101.com 16:38
great site for helping you learn them
unfortunately, no Raku on that site yet
venus007e :C 16:40
no raku
stevied but if you don't want to use regex, you could do a split method on the string and filter out undesired characters that way if you really want to use grep 16:41
venus007e how would that look? 16:42
stevied well, to tdo the split, you'd do: say $string.split('');
that returns a list (I think a list) 16:43
Nemokosch mmm, rather choose comb 16:45
if you really just want all characters one by one
split would give some awkward anchors in addition
stevied so then you would do: `my $new_string = $string.split('').grep(/\d/);`
Anton Antonov @Nemokosch#9980 Interesting / of course/
@Nemokosch#9980 Interesting / "of course."
stevied yeah, i'm not familiar with comb. haven't looked at that yet
actually, I guess you need a join after the grep
venus007e what is the /\d/?
stevied that's a pattern that means decimal digit 16:47
`my $new_string = $string.split('').grep(/\d/).join('');`
so that line splits the string into a list of individual characters, matches the ones that are digits and puts them into a list, and then rejoins the list to create a new string
probably not the most efficient way of doing it, but that's how you can use grep
venus007e cool 16:51
stevied but as pointed out, comb is better, for reasons I do not know
better than split
i can't tell if split returns a sequence or a list. i'm still fuzzy on a lot of this stuff myself 16:53
ok, it's a sequence. don't ask me the difference between a list and a sequence because I don't remember.
docs.raku.org/language/list 16:55
venus007e and how can i use grep, if i for excample only want the letters a, g and f? 16:57
stevied change the pattern to <[agf]> 16:59
`my $new_string = $string.split('').grep(/<[agf]>/).join('');` 17:00
read this basic guide: raku.guide/#_regular_expressions 17:01
you'll definitely want to know regular expressions
venus007e what do these do?
stevied find patterns in text 17:02
and answer questions for you: does this string contain the letter "a"?
18:11 wingfold left
MasterDuke stevied: isn't Bench running the code you give it multiples times and reporting the average time it took? so the total wallclock will be way more than the sum of the reported times 18:55
22:41 zacts joined 22:55 zacts left
stevied I don’t know. No idea how it works. That’s what I’m trying to understand. I just assumed bench ran the function and times that one function. 23:16
It seems pretty straightforward with Perl. The wall clock time matches the time on my watch. Why it would be different in raku I don’t know 23:17
Though in my second experiment, it did match my watch time in raku. No idea what accounts for the very different behavior 23:19