🦋 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 | |
00:06
daxim left
00:08
Petr37 left
00:09
Petr37 joined
00:10
daxim joined
00:14
oddp_ left
|
|||
codesections | Or, better/more readable: `sub f(@foo where [&] $_».isa(Int)) {}` | 00:14 | |
00:16
Petr37 left
00:31
leont_ left
|
|||
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 | ||
01:12
Altai-man_ joined
01:14
sena_kun left
01:21
ensamvarg3 joined
01:37
MilkmanDan left
01:40
kybr left
|
|||
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 | ||
01:45
kybr joined
01:51
MilkmanDan joined
01:54
ensamvarg3 left
01:58
xelxebar left,
rbt left
01:59
rbt joined
02:00
guifa2 left
02:08
xelxebar joined
02:09
holyghost left
02:10
molaf joined,
ensamvarg3 joined
02:15
wildtrees left
02:18
hungrydonkey left
02:23
hungrydonkey joined
02:36
hungrydonkey left
02:37
hungrydonkey joined
02:45
veesh left
02:51
xinming_ left
02:54
veesh joined
02:55
xinming_ joined
03:11
pilne left
03:13
sena_kun joined
03:14
Altai-man_ left
03:16
hungryd22 joined,
hungrydonkey left
03:32
abraxxa left
03:35
abraxxa joined
03:48
xinming_ left
03:50
xinming_ joined
04:05
holyghost joined
04:24
veesh left
04:33
veesh joined
04:51
vrurg left
04:52
vrurg joined
04:56
vrurg left
05:00
hungrydonkey joined,
hungryd22 left
05:06
abraxxa left,
abraxxa joined
05:12
Altai-man_ joined
05:14
sena_kun left
05:16
molaf left
05:23
andrzejku joined
05:28
vrurg joined
05:29
vrurg left,
vrurg joined
05:35
rindolf joined
05:44
ambs left,
ambs joined
06:01
rbt left
06:02
rbt joined
06:19
Sgeo left,
Sgeo joined
06:28
__jrjsmrtn__ joined
06:29
_jrjsmrtn left
06:37
Noisytoot left
06:44
tejr left
06:47
bocaneri left
06:48
bocaneri joined
06:49
tejr joined
06:54
xinming_ left
06:55
xinming_ joined
07:06
Zero_Dogg left
07:13
sena_kun joined,
Sgeo left
07:14
Altai-man_ left
07:15
Sgeo joined
07:18
Zero_Dogg joined
07:24
squashable6 left
07:25
squashable6 joined
07:26
squashable6 left
07:27
squashable6 joined
07:28
pecastro joined
07:29
ufobat joined,
ufobat_ joined,
ufobat_ left
07:31
Sgeo left
07:37
rindolf left
07:44
rindolf joined
07:46
rbt left
07:47
dakkar joined,
rbt joined
07:56
kensanata joined
08:10
leont joined
08:16
oddp_ joined
08:26
epony left
08:35
rindolf left
08:36
sena_kun1 joined
08:37
rindolf joined
08:39
sena_kun1 left
|
|||
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 | ||
08:51
lichtkind joined
09:03
epony joined
|
|||
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 | |
09:12
Altai-man_ joined
|
|||
holyghost | maybe a signal for the subprocess to kill it (calling exit) | 09:12 | |
or using process groups | |||
09:12
lichtkind_ joined
|
|||
holyghost | there's probably better perl6 syntax than that | 09:13 | |
09:14
sena_kun left
|
|||
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 | |||
09:15
lichtkind left
|
|||
Zero_Dogg | nod, I've been doing that, reading the Proc docs, but came up empty, hence asking here | 09:16 | |
09:19
sarna joined,
sarna left
09:32
patrickb joined
09:53
andrzejku left
|
|||
CIAvash | Zero_Dogg: I just used run to start a program and Ctrl+C killed it. How are you running a subprocess? | 09:53 | |
10:01
guifa2 joined
|
|||
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 | |
10:34
MasterDuke joined
10:37
Petr37 joined
10:38
Petr37 left,
Petr37 joined
|
|||
Petr37 | nice day 🌞 | 10:40 | |
tbrowder | g'day, raku people \o/ | 10:45 | |
10:49
xinming_ left,
xinming_ joined
10:50
rbt left
10:51
rbt joined
|
|||
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 | |
10:58
markoong joined
|
|||
tbrowder | i have always been a proponent of cpan over ecosystem since it has been available. | 10:59 | |
10:59
dogbert17 left
|
|||
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 | |
11:09
markong joined,
markoong left
|
|||
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 | |||
11:13
sena_kun joined
|
|||
Petr37 | thanks mortiz. where i can read about it? | 11:13 | |
abraxxa | that's neat for language detection | ||
unicode.org? | |||
11:14
Altai-man_ left
|
|||
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 | ||
11:17
sena_kun left
11:18
sena_kun joined
|
|||
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 | |
11:24
MasterDuke left
|
|||
kawaii | jnthn: or perhaps red herring, doesn't seem to be the cause :( github.com/shuppet/p6-api-discord/...kumod#L161 | 11:27 | |
11:28
jackji joined,
jackji left,
_jrjsmrtn joined,
__jrjsmrtn__ left
11:33
Black_Ribbon left
11:47
rbt left,
rbt joined
11:52
xinming_ left
11:55
xinming_ joined
11:56
cpan-raku left
|
|||
moritz | Guido mentions Raku: lwn.net/ml/python-ideas/CAP7+vJKsr...gmail.com/ :-) | 11:57 | |
12:00
cpan-raku joined,
cpan-raku left,
cpan-raku joined
12:11
rbt left,
rbt joined
12:14
xinming_ left,
xinming_ joined
|
|||
cpan-raku | New module released to CPAN! Log (0.3.1) by 03TYIL | 12:15 | |
12:47
markong left,
markoong joined
13:03
lichtkind_ left
13:12
Altai-man_ joined
13:14
sena_kun left
14:04
kktt007 joined
14:05
kktt007 left,
kktt007 joined
14:08
wamba joined
14:09
kktt007 left
14:10
Petr37 left
|
|||
lizmat thinks stackoverflow.com/questions/629142...ku-regexes is right up moritz alley :-) | 14:11 | ||
moritz | how did you know? :D | 14:15 | |
14:17
molaf joined
|
|||
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 | |
14:35
patrickb25 joined
14:37
patrickb left
14:43
wamba left
14:44
dataange` joined,
dataangel left
14:45
ufobat left,
ufobat joined
14:48
skids joined
15:02
markong joined
15:03
markoong left
15:13
sena_kun joined
15:14
Altai-man_ left
15:16
Petr37 joined
15:17
MilkmanDan left
15:29
patrickb joined
15:30
patrickb25 left
15:34
MilkmanDan joined
15:39
Petr37 left
15:51
rbt left
15:52
rbt joined
15:57
dolmen joined
16:01
markong left
|
|||
jjatria | Is there a way to take an option to MAIn multiple times? Like with "foo=s@" in Getopt::Long? | 16:07 | |
16:12
sno left,
sno joined
16:13
Sgeo joined
|
|||
[Coke] | I think MAIN(@foo)... then raku a.raku --foo=A --foo=B | 16:14 | |
that's not quite right | 16:15 | ||
16:16
kktt joined
16:17
Tirifto joined
|
|||
[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 | |
16:27
abraxxa left
16:35
dakkar left
16:37
vrurg left
16:38
vrurg joined
|
|||
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 | |
16:42
vrurg left
|
|||
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 | ||
16:48
xinming_ left
|
|||
AlexDaniel` | xD | 16:49 | |
I guess it's not smart enough | 16:50 | ||
but thank you anyway, tellable6 | |||
tellable6 | AlexDaniel`, It's my pleasure! | ||
16:50
_jrjsmrtn left
16:51
xinming_ joined,
__jrjsmrtn__ joined
17:02
OpenZen joined
17:11
vrurg joined
17:12
Altai-man_ joined
|
|||
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 | |
17:15
sena_kun left
|
|||
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 | |
17:36
ensamvarg3 left
|
|||
ShimmerFairy | IIRC ::?CLASS makes the most sense inside a role, since the actual class you end up running in could be anything. | 17:52 | |
18:03
hungrydonkey left
18:05
patrickb left,
ufobat left
18:13
_jrjsmrtn joined
18:15
__jrjsmrtn__ left,
Sgeo_ joined
18:16
fling left
18:19
Sgeo left
18:22
fling joined
18:25
kktt left
18:30
molaf left
|
|||
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 | |
18:41
wamba joined
19:01
xinming_ left,
xinming_ joined
19:02
Grauwolf left
|
|||
cpan-raku | New module released to CPAN! Net::IP (2.1.2) by 03TBROWDER | 19:03 | |
19:05
flash548 joined
19:06
MasterDuke joined
19:07
sena_kun joined
|
|||
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 | |
19:12
Grauwolf joined,
Grauwolf left,
Grauwolf joined,
sena_kun left
19:14
sena_kun joined,
Altai-man_ left
|
|||
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 | ||
19:20
cpan-raku left
19:23
cpan-raku joined,
cpan-raku left,
cpan-raku joined
|
|||
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 | |
19:28
RaycatWhoDat joined
19:29
sena_kun1 joined
|
|||
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 | ||
19:32
sena_kun1 left
|
|||
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 | |
19:38
Noisytoot joined
|
|||
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} | ||
19:42
molaf joined
|
|||
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 | |
19:45
sena_kun1 joined
19:49
Petr37 joined
|
|||
oddp_ | Sweet! Hope that ends up in the weekly once finished. Or is it intended for the advent calendar? | 19:58 | |
20:02
rindolf left
|
|||
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 | ||
20:15
flash548 left
20:19
[Sno] joined
20:21
xelxebar left
20:22
xelxebar joined,
sno left
20:25
Sgeo_ left
20:26
guifa2 left,
Sgeo joined
20:27
guifa2 joined
|
|||
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 | |||
20:48
sena_kun left,
sena_kun joined
20:49
sena_kun1 left
|
|||
rypervenche | guifa2: Oh...your document helped me finally understand what something like `my Str %foo{Rat}` means. Thanks! | 20:49 | |
20:53
wamba left
20:54
__jrjsmrtn__ joined
|
|||
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 | |
20:54
_jrjsmrtn left
21:03
wamba joined
|
|||
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 | |
21:10
kensanata left
21:12
Altai-man_ joined
21:14
sena_kun left
21:23
markong joined
21:32
markoong joined
21:33
markong left
|
|||
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 | |||
21:35
MasterDuke left
21:37
aborazmeh joined,
aborazmeh left,
aborazmeh joined
21:45
dataange` left,
dataangel joined
|
|||
Petr37 | what's means .eager? | 21:56 | |
22:09
Tirifto left
22:10
oneeggeach joined,
RaycatWhoDat left,
aborazmeh left
|
|||
guifa2 | Petr37: basically, it forces a list to evaluate if it's lazy | 22:12 | |
22:13
aborazmeh joined,
aborazmeh left,
aborazmeh joined
|
|||
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 | |
22:16
ensamvarg left
|
|||
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 | |
22:16
ensamvarg joined
|
|||
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 | ||
22:17
hungrydonkey joined
|
|||
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 | ||
22:21
aborazmeh left
|
|||
Petr37 | guifa2, thanks )) | 22:24 | |
22:24
skids left
|
|||
guifa2 | s/infinite/lazy | 22:27 | |
22:37
RaycatWhoDat joined
22:42
RaycatWhoDat left
22:47
xinming_ left,
xinming_ joined
22:52
oneeggeach left
|
|||
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 % | ||
23:13
sena_kun joined
|
|||
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 | |||
23:14
Altai-man_ left
|
|||
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! | |||
23:25
pecastro left
23:30
wamba left
|
|||
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 | |||
23:34
Black_Ribbon joined
23:36
MilkmanDan left
|
|||
guifa2 | oddp_ I believe ... is lazy by default | 23:38 | |
but maybe the @ sigil overrides that | |||
23:38
dolmen left
|
|||
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 | |
23:57
rbt left
|
|||
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 | |
23:58
rbt joined
|
|||
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 |