🦋 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.
fluca1978 hi, I don't remember, but is there a way to load a class by its name? Like my $foo = 'Bar'; $foo.new; 06:41
moritz_ m: my $name = 'Date'; say ::($name).new 06:47
camelia Cannot call Date.new with no parameters
in block <unit> at <tmp> line 1
moritz_ m: my $name = 'Date'; say ::($name).today 06:48
camelia 2021-04-07
moritz_ fluca1978: ^^ like this, with ::($name)
fluca1978 moritz_: thanks 06:49
moritz_ btw I just learned that the python equivalent of `Hash.keys` doesn't just return an iterator, but an iterable view on the hash keys that support membership test in O(1) 07:52
which is a pretty cool piece of technology, if you ask me
lizmat moritz_ care to elaborate how that would look in Raku ? 08:26
moritz_ lizmat: huh, good question. Maybe $key eq any(%h.keys()) ? 08:27
python has an "in" operator to test membership
lizmat $key (elem) %hash ? 08:28
moritz_ I guess raku's closest would be the set membership test?
lizmat yup
moritz_ $key (elem) %hash.keys()
lizmat that would work too, but not needed
m: my %h = a => 42; say "a" (elem) %h
camelia True
moritz_ does it currently work in O(1) or O(n)?
lizmat internally, that does an nqp::existskey 08:29
moon-child lizmat: you can do that in python too. The concern is, if you have a Hash.keys object and you didn't get a copy of the original hash, you should be able to ∈ on that without it needing to be O(n)
moritz_ so it doesn't re-build a hash-link thingy for the (elem) operator from a list?
lizmat (elem) on a list just tests each element in turn 08:31
and stops when a match is found
there's no point building a hash for that, as that would visit *each* element, wheras a short-circuiting linear search would look at all elements only in the worst case (no match) 08:32
jjatria samebchase-: FWIW, that's sounds to me like the problem I had when I wrote raku.land/cpan:JJATRIA/Timer::Stopwatch 10:11
samebchase- Does anyone know what's happening with the Grammars for binary effort? 10:50
jjatria: Thanks! Let me check out this library 10:51
samebchase- jjatria: the thing is I tried searching in modules.raku.org with combinations of "timeout", "channel", etc. but I guess I should have searched for "timer" 10:56
gist.github.com/alabamenhu/2fec7a8...4a2ae2f04d hmm 10:59
jjatria samebchase-: Yeah, naming things is hard, searching for them too :) 13:10
I think I was thinking of the Go time.Timer struct when working on that, which might explain why I went with that 13:11
I wrote about my initial use case here: pinguinorodriguez.cl/blog/porting-from-go
jraspass What's the raku equiv to Perl's custom charname aliases? perldoc.perl.org/charnames#CUSTOM-ALIASES , I found docs.raku.org/language/unicode#Name_aliases but it doesn't allow custom aliases afaict. 13:45
El_Che jjatria: interesting 13:46
lizmat jraspass: you can't atm afaik 14:00
jraspass I figured that would be the case, no worries. 14:16
demostanis[m] Does Raku have Perl5-like formats? 14:55
jmerelo demostanis[m]: yep. 14:56
demostanis[m] With same syntax?
jmerelo demostanis[m]:mostly, yes. Let me find the reference for you
demostanis[m]: I can't find it now. Give me a second. 14:58
demostanis[m]: So, I take it back. No, there's no such thing. Apparently, that was an initial intention, wasn't done eventually. 15:00
There are other templating systems you can use, however. But they are not native. 15:01
demostanis[m] That sucks... Was it not done because nobody was willing to do the work or for other reasons? 15:05
dakkar p5 formats are very global, and rely on global state… so they are a bit out of place in raku 15:06
jmerelo I don't really know... TBH, I didn't use it in Perl that much either. In the 90s, maybe. Now I would probably use YAML or JSON instead.
dakkar metacpan.org/pod/Perl6::Form this is probably what the proposal looked like 15:07
Altreus they're out of place in p5 15:27
wanting them is really asking what to do instead :D
demostanis[m] <Altreus "they're out of place in p5"> `s/p5/p6`? What would be better? 15:32
dakkar a templating system 15:34
(p5 format *are* a templating system, just a peculiar one)
samebchase- jjatria: Timer::Stopwatch is perfect for what I am trying to do! Thank you. 15:35
Altreus Yeah, although depending on your use case there may be more specific tools 15:39
not sure what template systems are available for raku except Cro::Template
presumably there's a mustache implementation 15:40
dakkar modules.raku.org/t/TEMPLATE more than one ☺ 15:42
Altreus Personally I've learned that the only things I ever want to template are HTML, and template languages are not complex enough for HTML 15:43
[Coke] realizes he doesn't need DOM::Tiny at all since there's an API he can use, whee. 15:44
Altreus better off with a dom manipulator
(Note: A manipulative dom may simply be abusive)
jjatria samebchase-: I'm glad to hear! 15:48
codesections «what template systems are available for raku except Cro::Template» the not-yet-released-as-alpha-but-nearly-there project I've been hacking on recently (Catkin) will be in a similar space 15:55
It's less of a tempting system and more of a functional way to generate HTML (or other text output) from pure Raku code -- similar to how React/similar systems work 15:56
dakkar codesections: ooh, interesting 15:57
codesections (well, except without the JSX layer in between, because Raku is flexible enough that we don't need it)
Altreus good because I hate doing { if condition } <span> {/if } ... {if condition} </span> {/if}
dakkar steal the nice bits, leave the nasty bits 😜 15:58
jdv79 i wrote a pretty decent "XML generator template" thing for something at $work just using heredocs 16:27
much more interesting than Perl's offering there 16:28
Wahnwitz hi there 16:40
codesections Wahnwitz: hi and welcome 16:43
Wahnwitz i am get stuck:)  .. I have a list with domain names. And i have a list with keywords. i would like to check whether a domain name contains one of the keywords. For now I read the keywords into a hash and the domain list is read with for (IO.lines). Is there a more elegant way rather than iterating over the keyword hash for each domain name?
hope thats clear :) 16:44
or.. is there a way to use contains(foo) without call it for each key element of an hash?   like   say "yea" if %hash.doesoneofthekeys.contains("bar") 16:47
jdv79 in Perl i might leverage the regex engine and build an alternation type pattern of all keywords and make one call for each of your haystacks (domain) 16:50
but Raku's regex engine is one of the worst performing parts so I'd not do that here. 16:51
codesections Wahnwitz, how about this: 16:53
m: my %kw = (:keyword-one, :keyword-two); say ['www.example.com', 'www.keyword-one.com', 'www.keyword-two.com'].grep: -> $dom { any %kw.keys.map: { $dom.contains: $_ }} 16:54
camelia (www.keyword-one.com www.keyword-two.com)
Wahnwitz i forgot to mention..i the hash i got pairs like "anwalt" -> "kategorie", "blabla" -> kategorie1" etc.. 16:55
ah..sorry 16:56
oke..so far its working..but i need to say the value of the key :) 16:59
Wahnwitz but "any" will help, thx for the hint 17:01
jdv79 i don't think junctions autothread paralelly yet do they? 17:03
lizmat no, they don't
jdv79 so that solution is "elegant" but in the future it *might* be more "performant" 17:04
lizmat yeah, 17:07
though I would not expect it ever to be actually threading unless we're looking at junctions with at least 10s of eigenstates
codesections m: my %kw = (:keyword-one<kat0>, :keyword-two<kat1>); say ['www.example.com', 'www.keyword-one.com', 'www.keyword-two.com'].map: -> $dom { |%kw.map({ $dom.contains(.key) ?? .value !! Empty }) } 17:08
camelia (kat0 kat1)
codesections ^^^ loses a bit in elegance/use of junctions, but prints the value.
lizmat jdv79: currently, I think it would make start to make sense at 10000+ eigenstates at the earliest to make a difference in wallclock
Wahnwitz wtf
wheres the trick that it say now the value? 17:09
Wahnwitz damn.. i forgot to say that the output need to be "domain;katN" :D 17:11
codesections m: my %kw = (:keyword-one<kat0>, :keyword-two<kat1>); say ['www.example.com', 'www.keyword-one.com', 'www.keyword-two.com'].map: -> $dom { |%kw.map({ $dom.contains(.key) ?? "$dom;{.value}" !! Empty }) }
camelia (www.keyword-one.com;kat0 www.keyword-two.com;kat1)
jdv79 lizmat: at that point might as well use a regex alternation approach once it performs well. geez;)
lizmat jdv79: well, perhaps :-) I'm just saying that at the current state of things, there's no real point in auto-threading of junctions yet 17:13
it would only slow things down
Wahnwitz Thats beautiful :) 17:14
lizmat and the static optimizer even changes something like $a == 1 | 2 | 3 into $a == 1 || $a == 2 || $a == 3
for sufficiently low number of eigenstates (forget if this was 2, 3 or 4)
jdv79 interesting. i think i've seen race speed things up with tens to hundreds and i'm assuming that's not terribly optimized yet. 17:15
Wahnwitz codesections: a last question (anyway thx alot so far) how would this work when i do not have a list rather that just a single domain name (because in the loop there are other checks to do) 17:16
jdv79 not really comparable though. apples to oranges.
codesections jdv79: tens to hundreds of items or batches?
Wahnwitz so (inside a loop) this works say $sld.map: -> $dom { |%branchen.map({ $dom.contains(.key) ?? "$dom;{.value}" !! Empty }) }
jdv79 items 17:17
Wahnwitz but i really dont need to map that single $sld value, right? 17:17
codesections right. just use it in place of $dom
codesections jdv79: interesting. When I've tried to use race, I haven't seen that sort of speedup. According to the docs, it has a default batch size of 64, so I thought there'd be 0 gain for ≤ 64 items (they'd all go to one worker). Am I confused, or are the docs wrong about the default batch size 17:25
lizmat no, that's correct 17:35
but you need a batch size that is large enough so that the batch isn't finished before the scheduler is ready to cue another job 17:36
otherwise you will never get parallelism
codesections yeah, I figured it was something like that (that is, I figured the default batch size was about as low as it could reasonably be, given the costs of parallelism -- which isn't exactly the same as not getting parallelism at all, but is similar in spirit) 17:39
Wahnwitz my %branchen = (:anwalt<recht>, :fussball<sport>); say "anwalt".map: -> $dom { |%branchen.map({ $dom.contains(.key) ?? "$dom;{.value}" !! Empty }) }; 17:40
evalable6 (anwalt;recht)
Wahnwitz that works..but since there is just one lingle label (anwalt) - .map seems to be not the way to go? 17:41
codesections m: my %branchen = (:anwalt<recht>, :fussball<sport>); say given "anwalt" -> $dom {|%branchen.map({ $dom.contains(.key) ?? "$dom;{.value}" !! Empty }) }; 17:43
camelia 5===SORRY!5=== Error while compiling <tmp>
Unsupported use of bare "say". In Raku please use: .say if you meant
to call it as a method on $_, or use an explicit invocant or argument,
or use &say to refer to the function as a noun.
at <tmp…
codesections m: my %branchen = (:anwalt<recht>, :fussball<sport>); say do given "anwalt" -> $dom {|%branchen.map({ $dom.contains(.key) ?? "$dom;{.value}" !! Empty }) };
camelia (anwalt;recht)
jdv79 i could be misremembering. it was when race and hyper were implemented and i was foolin with all the knobs...
Wahnwitz codesections so the block is bind to "do given" than? 17:44
codesections yeah. You could also put "anwalt" in a variable in any other way you like too, of course 17:45
Wahnwitz ahh..the block wont work with just using say 17:46
my %branchen = (:anwalt<recht>, :fussball<sport>); 17:47
my $sld = "anwalt"; say do given $sld { |%branchen.map({ $sld.contains(.key) ?? "$sld;{.value}" !! Empty }) };
jdv79 sometimes i get the feeling raku is a 100 year lang that will take 50 to achieve most of its aspirations;)
codesections yeah (which I forgot when first typing the above). By default, given is a statement and doesn't return a value for &say 17:48
Wahnwitz i see..thx again!
this is really sexy 17:49
codesections jdv79: well, part of the point of being a 100 year language is that we have the flexibility to adapt as we add _new_ aspirations. So I hope we'll still have aspirations to achieve in 50+ years -- I just hope they'll be different ones 17:50
similarly, I'm not entirely sure how many of our currently unfulfilled aspirations were goals from a long time ago/which are newly acquired 17:51
jdv79 yeah, i know. im more talking about the "original" (if there is such a thing) vision. basically Perl on steroids. 17:52
Wahnwitz hope so..but raku is really hard to learn
codesections unrelated question: an & reference to a sub is basically a pointer and thus pretty cheap to store/move, right? 17:53
m: sub f { say 'hi' }; my %h = (:key(&f)); %h<key>()
camelia hi
codesections e.g., storing &f in %h ^^^^ is not that costly/isn't copying anything large, right? 17:54
lizmat nope 17:55
Wahnwitz why not? 17:56
lizmat because everything in Raku is an object
so a sub is also an object
Wahnwitz and a reference on an object..is an object?
lizmat with a Perl mindset on, you could consider everything in Raku a reference 17:57
tobs jdv79: so then Raku is bash on steroids on steroids? :-)
lizmat so there's no reference to take
because you could argue, it is already a reference
jdv79 tobs: yes?;) 17:59
Wahnwitz probably with a little dose of LSD on top 18:02
lizmat
.oO( with the doors of perception wide open )
18:03
Wahnwitz :) 18:03
Wahnwitz codesections: the Junction operator(?) is not needed right? Is there a reason why you put it infront of the hash? 18:06
codesections oh, that | was a Slip operator, and isn't needed any more. In one of the earlier versions it was flattening the resulting list so that it wasn't nested. But now you're returning a Str, so it's not doing anything 18:10
Wahnwitz mhm.. i got the "lerning perl6" book from brian.. thats not mentioned there :) 18:11
jdv79 really? nothing bout "flat,Slip,|"? 18:13
Wahnwitz .slip yes - but not the use of | therefore
| is only described regarding Junctions (as far as i dig it..) 18:14
jdv79 might wanna shoot him an email. weird... 18:15
i havent read any books cept shitovs so far
Wahnwitz :D 18:16
Wahnwitz ah..the | is already described in the "flattening list" chapter, but in the index it only links to the Junction section 18:31
Wahnwitz mhm..just poking around...i have moved that way into a given statement and that wont work:  given $sld { when %branchen.map({ $sld.contains(.key) }) { say "yehhh"; } } 18:52
but it should?
seems that .key is missing there 18:53
%branchen.map({ $sld.contains(.key)}; could be seen as an iteration over %branchen .. or does I miss something? 18:56
MasterDuke you might want .first instead of .map? 18:57
Wahnwitz No such method 'reise' for invocant of type 'Str' 19:01
Did you try to smartmatch against a Pair specifically? If so, then the
key of the Pair should be a valid method name, not 'reise'.
"reise" is the value of the keyword in this case
Wahnwitz weird 19:01
Wahnwitz %branchen = (:anwalt<recht>, :fussball<sport>); my $sld = "anwalt"; given $sld { when %branchen.first({ $sld.contains(.key) }) { say "yehhh"; } } 19:06
m: %branchen = (:anwalt<recht>, :fussball<sport>); my $sld = "anwalt"; given $sld { when %branchen.first({ $sld.contains(.key) }) { say "yehhh"; } } 19:07
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable '%branchen' is not declared
at <tmp>:1
------> 3<BOL>7⏏5%branchen = (:anwalt<recht>, :fussball<s
Wahnwitz m: my %branchen = (:anwalt<recht>, :fussball<sport>); my $sld = "anwalt"; given $sld { when %branchen.first({ $sld.contains(.key) }) { say "yehhh"; } }
camelia No such method 'anwalt' for invocant of type 'Str'. Or did you try to
smartmatch against a Pair specifically? If so, then the key of the Pair
should be a valid method name, not 'anwalt'.
in block <unit> at <tmp> line 1
Wahnwitz m: my %branchen = (:anwalt<recht>, :fussball<sport>); my $sld = "anwalt"; say do given $sld { %branchen.map({ $sld.contains(.key) ?? "$sld;{.value}" !! Empty }) };
camelia (anwalt;recht)
Wahnwitz from my understanding it looks like very similar:/ 19:08
mhm ok.. putting the into another block helps 19:11
*map
m: my %branchen = (:anwalt<recht>, :fussball<sport>); my $sld = "anwalt"; given $sld { when { %branchen.first({ $sld.contains(.key) })} { say "yehhh"; } } 19:12
camelia yehhh
Wahnwitz oh noo....key is now outside of the block :D 19:17
Wahnwitz that drives me crazy.. 19:29
Doc_Holliwould as an entry for 99-bottles-of-beer.net/, is this too convoluted? pastebin.com/dykj69P1 21:21
Doc_Holliwood i need a new router 21:29
guifa Doc_Holliwood: nice 21:49
Doc_Holliwood uh, thanks. means something if it comes from you 21:50
Doc_Holliwood that probably sounded sarcastic. was not meant to be. 21:51
guifa One thing that’s interesting is the number of ways almost all of the lines can be done
guifa For instance, I tend to use { $n == 1 ?? ‘bottle’ !! ‘bottles’ }, just because it feels more maintanable if you were to switch to, I dunno, geese or something haha 21:53
moon-child I would prefer a separate function plur('bottle',$n)
Doc_Holliwood had that, i figured it would be distracting 21:54
guifa moon-child: yeah, for a larger project absolutely
Doc_Holliwood the sep function i mean
it is also known one can only put maximum of 10 geese on a wall =) 21:55
guifa The variable naming is good too, it helps showing what’s going on
Doc_Holliwood you can put up to 20 geese on a tree though 21:56
guifa 🌳🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢🦢
(okay those are swans but whatever, close enough) 21:57
Have you thought about using do at all? It’s kind of a cool variant of for that sometimes can read better than map 21:58
errm
do for
moon-child gather for could be cool too 21:58
guifa oh
yes
Doc_Holliwood gather for works
guifa take $one-down 21:59
guifa ^_^ 21:59
Doc_Holliwood m: say join "-", gather for 1..10;
camelia 5===SORRY!5=== Error while compiling <tmp>
Missing block
at <tmp>:1
------> 3say join "-", gather for 1..107⏏5;
expecting any of:
block or pointy block
Doc_Holliwood m: say join "-", gather for 1..10 { take $_ };
camelia 1-2-3-4-5-6-7-8-9-10
moon-child m: say join '-', gather .take for 1..10 22:00
camelia 1-2-3-4-5-6-7-8-9-10
guifa m: say join '-', do $_ for 1..10 # if you want to avoid taking 22:01
camelia 1-2-3-4-5-6-7-8-9-10
guifa Actually, it’s really cool how a song like that can show off so many different ways of doing stuff
Doc_Holliwood It's trickier than it looks because of the edge cases 22:03
if you simply hack it down you end up with nested ifs
and arguably ugly code
guifa is trying to think of a one liner for it haha 22:04
Doc_Holliwood good luck 22:05
i'm out for the night
guifa m: sub temp-change { CALLERS::<$*foo> = $*foo + 1  }; my $*foo = 0; say $*foo; { temp-change; say $*foo }; say $*foo 22:08
camelia 0
1
1
guifa is there naything I can do inside of temp-change so that the output is 0 1 0?
moon-child not quite the same, but 22:11
m: my $foo = 0; say $foo; { temp $foo = 1 + $foo; say $foo; }; say $foo 22:12
camelia 0
1
0
guifa moon-child: yeah, I’m trying to hide a setting in the dynamic variable that’s inserted into the symbol table with a ‘use’ statement 22:54
guifa and then have a sub adjust it for a lexical block 22:54
moon-child guifa: temp works for dynamic variables too. I don't think a sub can insert a declaration into its parent 23:40
but perhaps it would be possible to insert a LEAVE phaser?
(This is a little bit similar to the way that dynamic variables are approximated in s7 scheme)