🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
tbrowder g'day \o/ 12:31
lizmat tbrowder o/
tbrowder excitement reigns -- i used EVAL to create a formatted class successfully, thnx for the idea. now to see if i can make a class generator for it 12:33
formatter 12:34
lizmat :-)
tbrowder i feel sorry for python users. i could nevef get used to adding all those preamble things just to say something at the CLIo 12:35
back to work... 12:36
tbrowder i would appreciate any security experts to look at my eval sub to see if there is anything that looks like it could be turned into an breach: 14:35
gist.github.com/tbrowder/ac1857907...c27e9f15cc
thanks 14:36
*a breach 14:52
s/to look/looking/ 14:53
tonyo tbrowder: what is this to be used for? It doesnt look like eval is necessary 15:09
tbrowder for my dynamic creation of a formatter for DateTime. 15:16
tonyo Seems like you could just return a sub without eval 15:27
m: sub gen-fmt { return class :: does Callable { submethod CALL-ME (self, |c) { dd self; dd c; };};}; my $formatter = gen-fmt(); dd $formatter 15:29
camelia ===SORRY!=== Error while compiling <tmp>
Invalid typename 'self' in parameter declaration.
at <tmp>:1
------> does Callable { submethod CALL-ME (self⏏, |c) { dd self; dd c; };};}; my $format
tonyo m: sub gen-fmt { return class :: does Callable { submethod CALL-ME ($self, |c) { dd $self; dd c; };};}; my $formatter = gen-fmt(); dd $formatter 15:30
camelia <anon|1 $formatter = <anon|1>
tonyo tbrowder: ^^^ 15:31
m: sub gen-fmt { return class :: does Callable { submethod CALL-ME ($self, |c) { dd $self; dd c; };};}; my $formatter = gen-fmt(); $formatter()
camelia Too few positionals passed; expected at least 2 arguments but got only 1
in submethod CALL-ME at <tmp> line 1
in block <unit> at <tmp> line 1
tbrowder but i need to create on on the fly, a new one for each “info” 15:32
tonyo That will create a new one each time gen-fmt is called
m: sub gen-fmt { return class :: does Callable { submethod CALL-ME ($self, |c) { dd $self; dd c; };};}; my $f1 = gen-fmt(); my $f2 = gen-fmt(); dd $f1; dd $f2 15:33
camelia <anon|1 $f1 = <anon|1>
<anon|1 $f2 = <anon|1>
tbrowder it has to work with DateTime
tonyo Sorry, on my phone typing that in..that will work with datetime 15:34
Just restrict $self with DateTime:D and then it's not Callable by not a datetime
tbrowder look at my gist, how would you create a new fmt with new content and a custom, varying string after the DT attrs? 15:37
for instance, i want to be able to replace the Z with X. 15:39
or any string after the DateTime attributes. 15:41
tonyo Is your plan to have a lot of these factories? 16:21
(For different formats)
tbrowder yes 16:34
guifa You can avoid EVAL by returning an formatting algorith with an assuming, or an anon sub with closure.
RakuAST can do basic formatting stuff already, btw. I converted over Intl::Format::Numbers and it works well, although it hasn't been released to the ecosystem pending RakuAST 16:35
guifa is afk 16:37
tbrowder guifa: hm, sounds interesting. i should have looked at your code a long time ago but i wasn’t this deep into DT then 16:39
lizmat guifa: .assuming is just EVAL under the hood :-( 16:50
ugexe m: multi foo($*_ where { $_ == v6.c } = $*RAKU.version ) { say v6.c }; multi foo() { say $*RAKU.version }; foo() 17:06
camelia v6.d
ugexe m: use v6.c; multi foo($*_ where { $_ == v6.c } = $*RAKU.version ) { say v6.c }; multi foo() { say $*RAKU.version }; foo()
camelia v6.c
ugexe huehuehue 17:07
tbrowder lizmat: good to know. using the EVAL, my class generator seems ready for use. 17:43
hooray!
lizmat 🎉 17:44
guifa lizmat: ah yikes, is that why it's so slow? 20:04
lizmat guifa: well, most of the reason, yes 22:12