🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
Geth ¦ problem-solving: coke assigned to codesections Issue Consider renaming default branch from master to main github.com/Raku/problem-solving/issues/298 02:05
Geth doc: b00ffb3476 | (Daniel Sockwell)++ (committed by Juan Julián Merelo Guervós) | doc/Language/objects.pod6
Document attribute aliases

Part of the spec in Roast S12-class/attributes.t
  github.com/Raku/roast/blob/master/....t#L23-L33
05:26
linkable6 Link: docs.raku.org/language/objects
grondilu "fooooooo" ~~ /o+/; # how do I get the number of 'o's from $/ ? 10:05
$/.chars won't work if there was no o 10:07
m: "" ~~ /o+/; say $/.chars
camelia Use of Nil.chars coerced to empty string

in block <unit> at <tmp> line 1
grondilu m: "ooooo" ~~ /o+/; say $/.chars 10:08
camelia 5
immedlate What about `$/.defined ?? $/.chars !! 0` 10:19
m: "" ~~ /o+/; say $/.defined ?? $/.chars !! 0
camelia 0
immedlate "oOo" ~~ /o+/; say $/.defined ?? $/.chars !! 0
evalable6 1
immedlate or with `with`: `($/.chars with $/) or 0` 10:20
similarly `with $/ { $/.chars } else { 0 }`
or `without $/ { 0 } else { $/.chars }` 10:21
grondilu that's quite verbose
it's a bit of a hassle to have to deal with the special case of 0 10:22
raydiak could always just change the + to *
grondilu damb 10:23
*damn
Altreus or you could use the fact it didn't match "foooo" ~~ /o+/ ?? $/.chars !! 0;
in case your case is more complex 10:24
grondilu of course with * it works, I'm dumb, sorry 10:26
raydiak don't be too hard on yourself. with so many tools in reach it's easy to overlook one 10:28
Altreus We had a similar question the other day when the answer was to change the question :D 10:32
easily overlooked
gfldex m: "" ~~ /o+/; say +$/.?chars 10:59
camelia Use of Nil.chars coerced to empty string
0
in block <unit> at <tmp> line 1
gfldex m: "" ~~ /o+/; say +($/.?chars // 0) 11:00
camelia Use of Nil.chars coerced to empty string
0
in block <unit> at <tmp> line 1
gfldex m: "" ~~ /o+/; say ($/ // "").chars.Int
camelia 0
gfldex m: "ooo" ~~ /o+/; say ($/ // "").chars.Int
camelia 3
gfldex There may be a simple way to handle that in the Regex directly. 11:02
m: Nil.^methods.grep(*.name eq 'FALLBACK').say; 11:05
camelia (FALLBACK)
gfldex ok, .? on Nil is silly
grondilu iteration over a hash is undeterministic or something? 11:15
gfldex order of keys are randomised by design 11:16
grondilu ok, noted
Altreus kawaii_: by design! 11:17
grondilu I tried to count the number of leading zeros in a list with `+(@a ...^ +*)` but this hangs if @a is full of zeros. Any suggestion? 11:48
no loop please ;)
m: +((0, 0) ...^ +*) 11:50
camelia (timeout)WARNINGS for <tmp>: 11:51
grondilu m: say +((0, 0, 1) ...^ +*)
camelia 2
Altreus ok I can't parse that. What's going on there :D 11:55
grondilu again, I'm just trying to count the number of leading zeros in a list. 11:56
I bet there is a simple, nice way to do it but I don't see it. 11:57
Altreus yeah but I don't understand what the magic spell you wrote actually does
leading zeroes implies strings, no 11:58
oh
do you mean the number of zeroes in a list before the first nonzero
grondilu yes
Altreus gotcha
grondilu I don't want to write a loop. That would be lame. 11:59
Altreus is it just @a.first({ * != 0 }, :k) 12:00
i.e. the index of the first nonzero value
... plus one
no not plus one :D
grondilu m: say +(0, 0, 1).first: +* 12:01
camelia 1
grondilu m: say +(0, 0, 0, 1).first: +*
camelia 1
grondilu m: say +(0, 0, 0, 1).first: +*, :k
camelia 3
grondilu m: say +(0, 0, 0).first: +*, :k 12:02
camelia Use of Nil in numeric context
0
in block <unit> at <tmp> line 1
Altreus aha!
so it's that or the length of the list
grondilu couldn't I do that with a grep and a flip flop? 12:07
grondilu m: say <0 0 0 1 2 0>.grep({ 0 ff none(0)}) 12:12
camelia (0 0 0 1 0)
grondilu m: say <0 0 0 1 2 0>.grep({ 0 fff none(0)})
camelia (0 0 0 1 0)
grondilu m: say <0 0 0 1 2 0>.grep({ (state $ = 1) &&= !$_ }) 12:16
camelia (0 0 0) 12:17
grondilu I guess I'll use .first 12:18
gfldex grondilu: Do you mind if I qoute you on "I don't want to write a loop. That would be lame." ? :-> 12:25
grondilu well not sure I want to be quoted on that tbh ;) 12:28
I do hate writing loops though 12:29
Altreus explicit loops are rare in my experience
they're usually maps in disguise
raku certainly makes it a lot easier to avoid them 12:30
plus there's new structures like react-whenever, which I'm not sure whether they count as loops or not 12:31
gfldex m: multi sub prefix:«+\c[COMBINING RING ABOVE]»(\r) { r.defined ?? +r !! 0 }; say +̊(0, 0, 0).first: +̊*, :k; 12:43
camelia 0
gfldex And no, my terminal can display that operator correctly either. 12:44
gfldex Adds an item to the mischief list. 12:45
s/can/can't/
grondilu I'm confused by the ring above the opening parenthesis 12:46
the one above the * I get (I think) 12:47
gfldex grondilu: not even Firefox is displaying that one correctly 13:11
the circly is above the + but not centered 13:12
so the +̊( looks like a ligature 13:13
I don't think I'm gonna do that again…
immedlate what terminal do you use gfldex if you dont mind sharing 13:14
gfldex Putty+screen right now
gfldex immedlate: here is the complete setup gfldex.wordpress.com/2016/08/31/on...ingertips/ 13:15
Altreus looks fine for me 13:16
:)
so you did it right, at least :D
"No, it's the children who are wrong"
gfldex I'm not sure if I want to be right on your screen but not on mine. 13:17
Altreus Well I mean at least there's nothing for *you* to fix 13:18
grondilu gfldex: do you ssh from windows? 13:26
gfldex yes
grondilu do you know that the Windows terminal has a native ssh client now? 13:27
and the Windows terminal is actually good, with full unicode support for instance. 13:29
github.com/Microsoft/Terminal Microsoft has been quite open-source friendly lately. 13:30
gfldex grondilu: Does it work well with GNU Screen on the other end?
grondilu gfldex: I don't know about screen but I was using tmux with no issue. 13:31
Slaytanical i found: github.com/rakudo/rakudo/blob/mast...unning.pod and: github.com/ugexe/zef#more-cli are there more sources of environment variables i'd have to make myself aware of to isolate a raku environment to a USB drive? 14:08
or am i better off still compiling from source in something like msys2? 14:09
Xliff Hi! 14:12
Will a % parameter accept an Associative $? 14:13
m: sub a (%h) { say 'hash' }; my $a = 1 but Associative; a($a)
camelia hash
Xliff Hah!
Slaytanical nevermind on the msys2 bit, i forgot it's not an isolated environment really. 14:26
[Coke] wonders how quickly after a new set of unicode emojis is announced that they are available on win & mac. 14:30
(some nifty/funny ones in emoji/14)
codesections is there a good way to check the exit status of a command run with qx { }? I know I could add ; echo "$?" } to the end, but that feels a bit sloppy 14:48
(or just use &shell) 14:49
ugexe even if there was an e.g. $! for "last ran process exit status" it would be just as sloppy due to its inherit race condition 14:56
codesections m: say shell("invalid").exitcode 14:58
camelia /bin/sh: invalid: command not found
127
codesections ugexe: I'm not sure I understand? I was thinking of something like ^^^ but for qx. There's no race condition there, right? 14:59
ugexe if you want the Proc itself then why would you use qx? 15:00
so yes there is no race condition there
codesections fair enough. I guess I just like qx -- it feels less like I'm just passing strings around. But it isn't really, so I should probably just use shell 15:02
jdv even in the same thread it couldn't be fetched in a non-racy way? 15:06
codesections (it looks like the source for qx is at github.com/rakudo/rakudo/blob/mast...#L261-L265 In my ideal world, I think I'd have that return an IntStr that numifies to the exit code, the way Procs do) 15:08
jdv that seems like unnecessary magic but it might be easier than trying to get it to work if you fetched it in the next instruction or something like that 15:10
ugexe jdv, maybe but even then im not sure since i believe it uses async processes under the hood
jdv yeah, right... 15:11
forgot its built on async 15:15
Xliff codesections: gist.github.com/Xliff/b9d290cc5262...111434d7e9
codesections Xliff :) But that loses the ability to use arbitrary unicode pairs as the delimiter for qx, which is a big part of its appeal vs &shell, imo 15:20
ugexe and i guess even if it was in the same thread you'd then have to have the equiv of `my $!;` to keep processes spawned in other unrelated threads (not just reentrant ones) from setting it
gfldex codesections: do you get a non-0 exit code to indicate failure? If so, there is a module for that. 15:26
codesections gfldex oh? 15:31
melezhik :m sub foo ($a) {} 15:33
m: sub foo ($a) {}
camelia ( no output )
melezhik m: sub foo ($a) {}; foo(1);
camelia ( no output )
melezhik m: sub foo ($a) {}; my $a; foo($a);
camelia ( no output )
melezhik how can deal with this error - `Type check failed in binding to parameter '$user'; expected Any but got Mu (Mu)` ? 15:34
my function declared as `foo ($user) {}`
melezhik however if a $user is not defined and calls `foo($user)` I get this error 15:34
codesections the brute-force way is to declare it as `foo(Mu $user) {}`, but you might want to deal with the Mu before the callsite 15:35
melezhik I wonder why my function complains about this at all 15:36
for example it works fine when I do this: `my $user; foo($user)`
codesections well, the default constraint for params is Any. And the default type for $-sigiled vars is Any 15:37
so that works fine
melezhik github.com/melezhik/mybutterflies/...p.raku#L99
here $user and $token get passed by cro as cookes 15:38
cookies
melezhik and get this `mbf Type check failed in binding to parameter '$user'; expected Any but got Mu (Mu)` 15:38
changed the signature 15:40
codesections I suspect you want `get -> 'project', $project, 'edit-review', :$user! is cookie, :$token! is cookie` for that signature
Xliff codesections: Hmmm... good point. Would have to write a module with an included slang to get that working. :/
melezhik github.com/melezhik/mybutterflies/...d1f23be1a6
works fine nw
now
thanks codesections 15:41
codesections but note the difference between `:$user` and `:$user!` for Cro. The first matches *regardless* of whether the client has a user cookie (which is why it's sometimes Mu). The second only matches if the have a user cookie 15:42
melezhik ^^^ 15:43
melezhik yes, I am aware
cookies might not be set
codesections Ok, just making sure :)
gfldex codesections: see: github.com/gfldex/raku-shell-pipin...r-handling 16:13
melezhik hi Raku people! I've launched a better version of "My Butterflies" - a place where one can rate software they like. I'd appreciate for feedback from community. Eventually I am going to get a DSN and whatnots. But I am very interested to get a feedback before - 161.35.115.119/mbf/ 17:05
if someone wants to bragg about their projects - feel free - let me know and I put them to list. Raku projects are priority ... )))) 17:06
also please be nice, even though you review python stuff , ha-ha :') 17:08
daxim evalable6: subset List5 of List where .elems == 5; my @foo = List5.new: <q w e r t>; # how is this supposed to work? my List5 @bar = <q w e r t>?? 17:15
evalable6 (exit code 1) You cannot create an instance of this type (List5)
in block <unit> at /tmp/LaV96KsfdJ line 1
japhb subset List5 of List where .elems == 5; my @foo is List5 .= new: <q w e r t> 17:21
m: subset List5 of List where .elems == 5; my @foo is List5 .= new: <q w e r t>
camelia You cannot create an instance of this type (List5)
in block <unit> at <tmp> line 1
japhb Oh interesting
m: subset Array5 of Array where .elems == 5; my @foo := Array5.new: <q w e r t> 17:22
camelia You cannot create an instance of this type (Array5)
in block <unit> at <tmp> line 1
japhb hum 17:23
melezhik weekly: www.reddit.com/r/rakulang/comments...e_reviews/ 17:32
notable6 melezhik, Noted! (weekly)
Altreus melezhik: interesting idea but is there any moderation on what counts as software?
like, maybe you get raku and then maybe you get modules and then maybe you get ... functions?! I dunno
deduplication seems like a task as well 17:33
melezhik Altreus , that's the very idea of dog fooding, not only check the web site, but also test the idea itself. I am flexible, it could be any software and I have not yet decided on the level of granularity ... 17:38
I just think - it's cool to have a place where engineers write about software, honest, in depth reviews, instead of smarmy marketing stuff ... 17:39
and I like to check it with raku community first, before expand to other languages/communities ... 17:40
Geth doc: 2faaff0c55 | Coke++ | xt/word-variants.t
whitespace
17:46
grondilu you know, I wish there was a $*MODULUS environment variable to set up modular arithmetics. Wouldn't that be neat for crypto stuff? 18:49
Could this be done in user/module space? 18:50
lizmat m: PROCESS:<$FOO> := 42; say $*FOO # yes ?
camelia 5===SORRY!5=== Error while compiling <tmp>
Preceding context expects a term, but found infix := instead.
at <tmp>:1
------> 3PROCESS:<$FOO> :=7⏏5 42; say $*FOO # yes ?
lizmat m: PROCESS::<$FOO> := 42; say $*FOO # yes ?
camelia 42
grondilu I know setting the variable can be done, but could it be made to affect Int arithmetics? 18:51
lizmat ah. that? not without affecting performance of *all* Int arithmetic 18:52
grondilu what about changing the interpretation of literal integers? That could be done, right? 18:55
from user code, I mean. 18:56
with macros or something?
lizmat possibly
moon-child grondilu: what are you trying to do? 18:57
grondilu use Mod13; say 12 + 1; # 0 18:59
lizmat use Mod13 could export a proto infix:<+> with all new candidates 19:01
so you *can* do that in a module
grondilu indeed, not sure why I didn't see it that way. 19:02
hang on 19:03
lizmat it will *only* affect that lexical scope, yes 19:04
grondilu I can't override core candidates, can I?
lizmat sure you can, by exporting a proto
grondilu ok but inside that candidate how would I call the core ones? 19:05
moon-child lizmat: I thought operator overloads sometimes had dynamic scope, at least conceptually
there was a pr not long ago to make sort respect overridden &[cmp]
lizmat m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { 42 }; say 999 + 42e0 19:07
camelia 5===SORRY!5=== Error while compiling <tmp>
Calling infix:<+>(Int, Num) will never work with any of these multi signatures:
(Int \a, Int \b)
at <tmp>:1
------> 3nfix:<+>(Int \a,Int \b) { 42 }; say 999 7⏏5+ 42e0
lizmat m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { 42 }; say 999 + 666 19:08
camelia 42
lizmat moon-child: yeah, but the problem is that &[cmp] is that List.sort *lexically* only sees the &cmp of the core
and the question is: should it only look lexically for that, or also dynamically 19:09
and that's what the PR is about
grondilu m: dd &COMPUNIT::infix:<+> 19:10
camelia Any element{'&infix:<+>'} = Any
grondilu m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { &COMPUNT::infix<+>(a, b) mod 13; }; say 12 + 1 19:11
camelia Cannot resolve caller infix:<mod>(List:D, Int:D); none of these signatures match:
(Real $a, Real $b)
in sub infix:<+> at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { &COMPUNIT::infix<+>(a, b) mod 13; }; say 12 + 1
camelia Cannot resolve caller infix:<mod>(List:D, Int:D); none of these signatures match:
(Real $a, Real $b)
in sub infix:<+> at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu see what I mean? 19:12
moon-child hmm, there may be an easier way
one moment
grondilu maybe with the routine form of the operators. Not sure what it is though 19:13
moon-child hmm, no. I thought you might be able to say: augment class Int { method new(\x) { self.bless(x mod 13) } }. But apparently it has to be a multi, and that candidate never gets selected 19:15
grondilu I could make a role of course 19:20
grondilu like, my $n = 7 but Modular(13); or somethinp 19:22
but I think I had tried that before and I still didn't like it. Too verbose.
moon-child you could just overload == and leave all the other operators the same 19:23
grondilu well that would be inefficient. And that wouldn't work for modular inverse. 19:24
making a role was kind of messy too because of the possibility of having several modulus in an expression. 19:25
like what to do with (5 but Modulo(13)) + (6 but Modulo(7)) 19:26
thus me thinking of having a single modulus as an environment variable. 19:27
oh wait isn't there a keyword to delegate a method to the next candidate or something? 19:31
moon-child nextsame? 19:32
grondilu yeah, under "re-dispatching" in the docs 19:33
m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { callsame mod 13; }; say 12 + 1
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared routine:
mod used at line 1
grondilu m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { callsame() mod 13; }; say 12 + 1
camelia Cannot resolve caller infix:<mod>(Nil:U, Int:D); none of these signatures match:
(Real $a, Real $b)
in sub infix:<+> at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { callsame(); }; say 12 + 1 19:35
camelia Nil
grondilu m: proto infix:<+>(|) {*}; multi sub infix:<+>(Int \a,Int \b) { return callsame(); }; say 12 + 1
camelia Nil
grondilu whispers
moon-child because the builtin &[+] isn't a candidate for the new proto you just made 19:36
grondilu oh yeah makes sense
so I overwrite everything or nothing, I guess. That's not very useful. 19:39
lizmat note that you *can* override all and still access the old 19:42
grondilu Maybe I should just define a 'm' suffix. 19:44
lizmat m: BEGIN my &old = &infix:<+>; proto sub infix:<+>(|) {*}; multi sub infix:<+>(\a, \b) { old(a,b) }; say 42 + 666
camelia 708
lizmat m: BEGIN my &old = &infix:<+>; proto sub infix:<+>(|) {*}; multi sub infix:<+>(\a, \b) { old(a,b) }; my $a = 42; say $a + 666
camelia 708
grondilu neat trick 19:45
lizmat grondilu: ^^ between the proto and the catchall, you can insert your own candidates
grondilu m: BEGIN my &old = &infix:<+>; proto sub infix:<+>(|) {*}; multi sub infix:<+>(\a, \b) { old(a,b) mod 13 }; say 12 + 1 19:46
camelia 0
grondilu nice
so it's feasible 19:48
grondilu I'm so going to write a secp256k1 module now ;) 19:50
lizmat ++grondilu 19:59
melezhik how can I remove cookies using cro ? 21:19
I have very strange bug when my cookies works fine when tested with safari and I see random issues with working with another browsers, like Mozilla 21:23
for mbf - 161.35.115.119/mbf/
I don't think that cookies format is specific to browsers? 21:24
basically I use standard cro function - github.com/melezhik/mybutterflies/....raku#L232
to set cookies on server side ...
that is it
duck duck go browser works fine as well ... 21:28
yeah, just checked things, looks like does not work properly in Firefox (( 21:31
melezhik github.com/croservices/cro-http/issues/155 21:50
melezhik if cro caches GET requests? if so, how to disable this cache? 22:15