🦋 Welcome to Raku! raku.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: colabti.org/irclogger/irclogger_log/raku
Set by ChanServ on 14 October 2019.
codesections And, building on that, if I really want a the type to be enforced based on the runtime contents of the Array, I guess I could do something like this: 00:04
m: sub f(@foo where { @foo.map({.isa(Int)}).all }) { @foo.sum }; f(<a, b, c>)
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got List ($("a,", "b,", "c"))
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
codesections although the error message isn't super great there. But at least it tells the user that they're calling &f incorrectly 00:05
codesections Or, better/more readable: `sub f(@foo where [&] $_».isa(Int)) {}` 00:14
guifa2 codesections: actually evne easier 00:35
sub f(@foo where .all ~~ Int) { … }
codesections guifa2: oh, wow, that is a lot easier. Thanks :) 00:36
guifa2 You could also do
codesections I should never forget about smartmatching
guifa2 sub f(@foo where .all.isa: Int)
But I think in this case smartmatching is cleaner
I can't remember who it was — I think actually it was DrForr :-( — who said grying to avoid parantheses in Raku is a cool way of showing off/learning its features 00:37
and makes for readable code to boot
codesections actually, guifa2: I don't think the second works. (The smart matching does, though :) ) For the second: 00:44
m: sub f(@foo where .all.isa: Int) {@foo.sum}; f([1, 1]);
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
codesections which is because
m: [1, 1].all 00:45
camelia ( no output )
codesections m: say [1, 1].all
camelia all(1, 1)
codesections m: say [1, 1].all.isa: Int
camelia False
guifa2 codesections: hrm, that's weird that it doesn't work 01:41
I think the problem is that the .isa is running on the junction, rather passing through to the elements 01:43
SmokeMachine m: sub f(@foo where .all ~~ Int) {@foo.sum}; f([1, 1]); 08:43
camelia ( no output )
SmokeMachine m: sub f(@foo where .all.^isa: Int) {@foo.sum}; f([1, 1]);
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: say 1.^isa: Int 08:44
camelia 1
SmokeMachine m: say [1,1].all.^isa: Int
camelia 0
SmokeMachine m: say [1,1].all.&{.^isa: Int }
camelia 0
SmokeMachine m: say [1,1].all ~~ Int 08:45
camelia True
SmokeMachine m: sub f(@foo where [&&] $_».^isa(Int)) {@foo.sum}; f([1, 1]); 08:46
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: sub f(@foo where { [&&] $_».^isa(Int) }) {@foo.sum}; f([1, 1]); 08:47
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: sub f(@foo where { $_».^isa(Int).all }) {@foo.sum}; f([1, 1]);
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: say [1,1]>>.^isa(Int) 08:48
camelia 0
SmokeMachine m: say [1,1].map: *.^isa(Int)
camelia (1 1)
SmokeMachine m: say [1,1].map(.^isa(Int)).all
camelia Cannot map a Array using '0'
Did a * (Whatever) get absorbed by a list?
in block <unit> at <tmp> line 1
SmokeMachine m: say [1,1].map(*.^isa(Int)).all 08:49
camelia all(1, 1)
SmokeMachine m: sub f(@foo where .map(*.^isa(Int)).all) {@foo.sum}; f([1, 1]);
camelia Constraint type check failed in binding to parameter '@foo'; expected anonymous constraint to be met but got Array ($[1, 1])
in sub f at <tmp> line 1
in block <unit> at <tmp> line 1
SmokeMachine m: sub f(@foo where { .map({ .^isa(Int) }).all }) {@foo.sum}; f([1, 1]); 08:50
camelia ( no output )
SmokeMachine m: sub f(@foo where { .map({ .^isa(Int) }).all }) {@foo.sum}; say f([1, 1]);
camelia 2
Zero_Dogg I'm running a subprosess with 'run' (ie. in the foreground). If I do ^C the raku app exits, but the subprocess sticks around. How can I make sure the subprocess gets reaped? 09:08
holyghost if you double fork you hve to shoot the process (if that's how run works AFAIK) 09:09
Zero_Dogg holyghost: nod, the thing is, run is blocking, so my app is just sitting there waiting for the subprocess to exit 09:10
holyghost maybe a signal for the subprocess to kill it (calling exit) 09:12
or using process groups
holyghost there's probably better perl6 syntax than that 09:13
Zero_Dogg in perl I used to do that kind of thing, but since run is blocking, I don't actually have the PID. I could switch to Proc::Async, and gather PIDs and set up signal handlers, but this does seem to me like something the language might already have something for. 09:15
holyghost indeed, I would search in the docs
I dunno any further
Zero_Dogg nod, I've been doing that, reading the Proc docs, but came up empty, hence asking here 09:16
CIAvash Zero_Dogg: I just used run to start a program and Ctrl+C killed it. How are you running a subprocess? 09:53
CIAvash Zero_Dogg: anyway, you can probably write `my $proc = run ...` and then use $proc.pid. But it seems the Proc::Async has a kill method. 10:33
Petr37 nice day 🌞 10:40
tbrowder g'day, raku people \o/ 10:45
tbrowder i'm rakuizing my p6 modules and want to rename the repos on github from -Perl6 to -Raku. that would require a change to the source urls in META6.json. given that the affected audience is very small and any users are probably cutting edge types and my releases are on cpan, think the change would not cause but a tiny ripple. 10:52
opinions, please
*i think...
abraxxa don't use language namse in repo names ;) 10:53
if you want to keep the old versions installable via github: fork them to the new name
Altai-man_ abraxxa, github will keep redirects to new repo.
tbrowder that horse had left the barn. that was my attempt at marketing. but now i would be ok with eliminating the -Raku also. 10:54
abraxxa is that guaranteed? if yes for how long?
and he didn't say that he's using github
Altai-man_ abraxxa, yes. How long, hmm. Not sure, IIRC until a new repo is created under this user and the same name.
tbrowder i am using github 10:55
Altai-man_ abraxxa, source-url in META have github source, I assume.
tbrowder yes
abraxxa another option I can think of is switch to CPAN 10:56
hm...how does zef get this META6.json file?
tbrowder all my modules are on cpan
abraxxa looks like a hen-and-egg problem to me
I thought the point is to keep them installable from github
tbrowder zef would always find the source for each because they are all on cpan. they are NOT in the "ecosystem" listing 10:57
tbrowder i have always been a proponent of cpan over ecosystem since it has been available. 10:59
abraxxa I don't get what you're 'fear' (sorry, no native speaker, can't think of a better word) about just renaming the repos is? 10:59
tbrowder no fear, just want to make sure such a move wouldn't cause trouble and getting other opinions. thanks. 11:00
Altai-man_ tbrowder, giving redirects are in place and you are using cpan, nothing to be afraid of should happen. You still can rename some less prominent repo and try next day if it's installable. :)
tbrowder ok, sounds good. thank you. 11:01
bye
abraxxa :) 11:04
Petr37 what is Unicode property? 11:08
moritz Petr37: you can ask questions about characters, like "Is this a number?", "is this a word separator?", "Is this part of Cyrillic script?" etc. 11:11
Petr37: Unicode properties are an attempt to organize characters along such questions
Petr37 thanks mortiz. where i can read about it? 11:13
abraxxa that's neat for language detection
unicode.org?
moritz or en.wikipedia.org/wiki/Unicode_char...r_property 11:14
Petr37 moritz, thanks ) 11:16
kawaii Hi, not sure how best to phrase my question/issue - I have a live supply which is sending me _historical_ events when tapped. Not really sure how to go forward with debugging how or why, but we have a GH issue on our project here: github.com/shuppet/p6-api-discord/issues/38
jnthn I think it's maybe not as live as you think... :) Did you use a Supplier::Preserving somewhere, for example? 11:19
kawaii Ah, this is already a good hint, I will do some searching. :) 11:22
Zero_Dogg CIAvash: I think the program I'm running is doing something funky to ignore it, so I might need to go the Proc::Async route, just need to find a clean way to do it 11:23
kawaii jnthn: or perhaps red herring, doesn't seem to be the cause :( github.com/shuppet/p6-api-discord/...kumod#L161 11:27
moritz Guido mentions Raku: lwn.net/ml/python-ideas/CAP7+vJKsr...gmail.com/ :-) 11:57
cpan-raku New module released to CPAN! Log (0.3.1) by 03TYIL 12:15
lizmat thinks stackoverflow.com/questions/629142...ku-regexes is right up moritz alley :-) 14:11
moritz how did you know? :D 14:15
moritz answered 14:25
I hope the plug for my book isn't taken as spam 14:26
[Coke] it was short and after a detailed answer, so I hope not 14:31
jjatria Is there a way to take an option to MAIn multiple times? Like with "foo=s@" in Getopt::Long? 16:07
[Coke] I think MAIN(@foo)... then raku a.raku --foo=A --foo=B 16:14
that's not quite right 16:15
[Coke] sub MAIN(:@foo) { ... } 16:19
^^
jjatria Huh, yeah, that works. I thought I had tried that but I guess I messed up somewhere. Thanks! 16:21
[Coke] np 16:26
guifa2 moritz: it's interesting to see the love for parantheses. I was just commenting last night in here about how eschewing parentheses in Raku can lead to some really easy-to-follow code 16:39
guifa2 abraxxa: unfortunately for language detection it's only a semi-useful proxy, especially in some of the newer methods that try to nail things down over only a few words of text. Use one Japanese character in an emoticon and suddenly it assumses it's all in Japanese lol 16:46
tellable6 guifa2, I'll pass your message to abraxxa
guifa2 tellable6: ty 16:47
tellable6 guifa2, I haven't seen ty around, did you mean tyil?
guifa2 ... lol
AlexDaniel` xD 16:49
I guess it's not smart enough 16:50
but thank you anyway, tellable6
tellable6 AlexDaniel`, It's my pleasure!
guifa2 Is there any particular reason to use ::?CLASS instead of just, well, the class name? Was it just to make refactoring without an IDE easier? 17:14
moritz guifa2: the problem is that in python, a bare function already has a different meaning (a reference to the function) 17:29
guifa2 moritz: Yeah, but the thread was mostly people talking about readability, rather than compatibility
moritz guifa2: so if you allow both `foo` and `foo 42`, after parsing the `foo` the parser doesn't know whether to expect a term or an infix 17:30
which is where the backtracking comes in that Guido talked about early in his mail
which I find pretty concerning in such a central place of the grammar
guifa2 Yeah, the technical critique I couldn't argue with 17:35
ShimmerFairy IIRC ::?CLASS makes the most sense inside a role, since the actual class you end up running in could be anything. 17:52
guifa2 ShimmerFairy: if it were just ::C that would make sense, but ::?CLASS Is a compile time var, so it's only usable by the given class (I mean, I know there's ways to get around that, but you couldn't do class A { method b (::?CLASS:) }; my &b = A.^find_method('b'); my C { ; }; C.new.&b because the ::?CLASS is hardwired to A and won't match the C invocant. 18:33
cpan-raku New module released to CPAN! Net::IP (2.1.2) by 03TBROWDER 19:03
flash548 raku newb here, why does this p5 oneliner work: perl -e 'print "\033[0;10H";' while this raku doesn't perl6 -e 'print "\033[0;10H";' ... the raku variant just prints the literal string (doesn't move the terminal cursor). 19:08
rypervenche flash548: I know that you can replace \033 with \e and it will work. 19:15
flash548: Ahh, what you want is \o33 instead of \033
flash548 ohhh, yeah I just tried that - yes it works - thank you! 19:16
moritz or \o[33]
flash548 awesome
codesections Why is it that I can say the first one of these type constraints, but not the second? 19:24
m: my %h{Str} of Int = foo => 1; say %h;
camelia {foo => 1}
codesections m: sub f(--> %{Str} of Int) {my %h{Str} of Int = foo => 1} ; say f
camelia 5===SORRY!5=== Error while compiling <tmp>
Malformed return value
at <tmp>:1
------> 3sub f(-->7⏏5 %{Str} of Int) {my %h{Str} of Int = foo
codesections and (related) *is* there a way to dwim for constraining the return type? 19:25
MasterDuke might have to define a subset beforehand and use that 19:29
there are (at least currently) more restrictions on what you can put for a return type 19:30
iirc
RaycatWhoDat Hi! I just ran into a situation where I needed to split each line of a file into its own uniquely-named file. I reached for Raku and it was done in like, maybe five minutes. :) This language is ridiculously good and worth it, slow startup be damned.
Just wanted to spread the good news! 19:31
rypervenche RaycatWhoDat: Very happy to hear that :) Feel free to share the news with non-Rakuuns. :) 19:34
Have we decided on a good spelling for Rakun/Rakuun? 19:35
codesections Is that the demonym? I'd been kind of wondering what it was 19:36
rypervenche I know there are a few different ones floating around. I quite like Rakuun :) 19:38
codesections I guess it could be spelled Rakün, to sort of match »ö« 19:39
moritz as a native speaker for a language that uses the ü character, I object :D
codesections Fair enough :D 19:40
rypervenche Not bad logic, but yeah, when some people won't be able to type it, we'd end up with at least 2 variations of it at that point.
guifa2 codesections: how about this? 19:41
m: sub f(--> Hash[Int,Str]) { my %h{Str} of Int = foo => 1 }; say f
camelia {foo => 1}
guifa2 I should probably go back and finish my Strongly Typed Raku guide (but take a look and please give me feedback! gist.github.com/alabamenhu/3877fa6...d1661f69f9 ) 19:42
rypervenche Ooooh, this looks good. 19:43
oddp_ Sweet! Hope that ends up in the weekly once finished. Or is it intended for the advent calendar? 19:58
moritz guifa2: there's no FatInt iirc 20:02
guifa2 moritz: ty when I wrote it ages ago it was done mostly from memory, hence the little mistakes across it that I need to touch up now that I've got time 20:03
moritz: and also FatRat isn't a subclass of Rat so… that line gets deleted :-) 20:06
moritz guifa2: another gotcha to maybe point out is with lazy lists/iterators/streams
that you cannot post-hoc validate the types of the elements without actually exhausting the iterator 20:07
guifa2 AAh, didn't even think about that. I don't use them as much so not fresh on my mind
codesections :guifa2 Thanks, `--> Hash[Int, Str]` was exactly what I was looking for! Is there any particular logic to why that syntax works for return types but not variables and the `%{Str} of Int` syntax works for variables but not return types? Or is it just one of those things we need to remember? 20:28
guifa2 Actually it works fine for variables :-)
codesections (I'm reading your draft guide now; it looks like it'll be a great addition to the docs, by the way:D ) 20:29
guifa2 my Hash[Int, Str] $foo = Hash[Int, Str].new: :1a, :2b, :3c
codesections Aha
guifa2 but then you're in a scalar container
to stay in a hashy one 20:30
my Int %foo{Str}
Note that the default key is Str so you can just say my Int %foo 20:31
codesections ok, with you so far. But then why doesn't the `my Hash[Int, Str]` syntax work with literal syntax? 20:32
m: my Hash[Int, Str] $foo = {:foo(1)}
camelia Type check failed in assignment to $foo; expected Hash[Int,Str] but got Hash (${:foo(1)})
in block <unit> at <tmp> line 1
guifa2 literal syntax uses scalar assignment, rather than hash assignments 20:33
it's.... complicated lol
codesections But `$foo` is a scalar, right? in `my Hash[Int, Str] $foo = Hash[Int, Str].new(…)`, I mean 20:34
"it's.... complicated" I'm getting that impression! But *really* powerful, too. And I really appreciate your help in understanding all the nuances :) 20:35
moritz assignment to a % or @ sigil is really coercive 20:46
you can do
my @a = 42
and it works, even though 42 is not an array 20:47
and that's the reason that my Int @a = 1, 2; also works
scalar assignment has no such magic
rypervenche guifa2: Oh...your document helped me finally understand what something like `my Str %foo{Rat}` means. Thanks! 20:49
codesections Oh, `{:foo(1)}` is syntactic sugar for `Hash.new('foo', 1)`, which returns an Hash (w/o) type constraints. Whereas `Hash[Int,Str].new('foo', 1)` returns a type constrained Hash! I see the difference now 20:54
codesections (still reading that guide. This is totally unrelated to typing, but I had no idea you could do `given @a { .[0] }`. That's very cool) 21:04
cpan-raku New module released to CPAN! Sparrow6 (0.0.25) by 03MELEZHIK 21:34
New module released to CPAN! Sparrowdo (0.1.9) by 03MELEZHIK
Petr37 what's means .eager? 21:56
guifa2 Petr37: basically, it forces a list to evaluate if it's lazy 22:12
guifa2 m: my @a = lazy given ^10 { say "Creating element $_ "; take $_ }; say "I need ", @a[2] 22:13
camelia Creating element 0 1 2 3 4 5 6 7 8 9
take without gather
in code at <tmp> line 1
in block <unit> at <tmp> line 1
guifa2 err
not given lol
m: my @a = lazy gather ^10 { say "Creating element $_ "; take $_ }; say "I need ", @a[2]
camelia 5===SORRY!5=== Error while compiling <tmp>
Unexpected block in infix position (missing statement control word before the expression?)
at <tmp>:1
------> 3my @a = lazy gather ^107⏏5 { say "Creating element $_ "; take $_ }
expectin…
guifa2 m: my @a = lazy gather for ^10 { say "Creating element $_ "; take $_ }; say "I need ", @a[2] 22:14
camelia Creating element 0
Creating element 1
Creating element 2
I need 2
guifa2 There we go. Notice how the @a will eventually contain 10 elements, but when I ask for the 3rd (index 2), it only creates as many as are needed
codesections "not given lol" I think I've been writing too much code. I read that as "Not given a list of lists" 22:15
guifa2 A lot of lists are actually lazy. For instance, if you do @a = 0, 2, 4 ... 1000; you'll get an infinite list of every other number up to 1000, but the elements won't be created unless they're needed. The problem with lazy lists is that often you don't know how many elements there are. So you can call .eager on it to force the entire list to be evaluated. 22:16
guifa2 If your list is infinite, though, it will result in a hung program 22:16
codesections: given is a great feature. Especially since you can given multiples and do wildcards 22:17
codesections agreed. It reminds me as a better version of Rust's `match` expressions, which people (rightly) rave about 22:18
guifa2 codesections: see tenesianu.blogspot.com/2019/05/per...roids.html
Petr37 guifa2, thanks )) 22:24
guifa2 s/infinite/lazy 22:27
oddp_ guifa2, regarding that blog post, is the following documented somewhere? "In Perl 6, given can take one or more arguments and will try to match each of them to the values for each when block" 23:04
guifa2 oddp_: Not as such. 23:06
oddp_ Seems to break apart when used with booleans. Think fizzbuzz: $_ % 3, $_ % 5
guifa2 In reality, given $foo { when $bar { … } } decides if the when clause should be running by doing $foo ~~ $bar 23:07
oddp_ Oh, stringifying a list? 23:08
Okay.
guifa2 Lists smart match by smart matching each element... so it's,um, smart :-) 23:09
Note that $_ % 3 doesn't return a Bool, but an Int, so it will always smart match True 23:11
oddp_ Yeah, my client escaped the double %
guifa2 Not sure why the Bool matching is off 23:13
I would do fizzbuzz like this
tio.run/##K0gtyjH7/z8tv0ghzshAQddO...RC1X7f//AA
aaaah! 23:14
duh
guifa2 Smartmatch against False always fails; if you mean to test the topic for truthiness, use :!so or *.not or !* instead at /home/runner/.code.tio:1 23:14
oddp_ Sure, was just the first example that popped into my mind. 23:15
Oh, okay, good to know. Thanks for that!
oddp_ "if you do @a = 0, 2, 4 ... 1000; [...] won't be created unless they're needed" -- Isn't @a forcing an evaluation here? 23:31
Hm, seems to hang with ... 1_000_000_000
guifa2 oddp_ I believe ... is lazy by default 23:38
but maybe the @ sigil overrides that
oddp_ Strange, $a hangs as well. Anyways, will figure it out. Thanks for going out of your way to help us noobs in here. :) 23:40
guifa2 oddp_: actually yeah, the @ does override it 23:57
guifa2 can provide it using 23:57
m: my @a = 0, 2, { say $^a + 2; $a + 2 } ... 10;
camelia 4
6
8
10
guifa2 vs 23:58
guifa2 m: my @a = lazy 0, 2, { say $^a + 2; $a + 2 } ... 10; say "not evaled yet"; @a[4] 23:58
camelia not evaled yet
4
6
8