🦋 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.
Nemokosch ^ means beginning of string 01:13
^^ means beginning of line
lizmat weekly: www.reddit.com/r/rakulang/comments...ence_2022/ 10:25
notable6 lizmat, Noted! (weekly)
grondilu Hi 10:52
I realized I followed the wrong track for my project, yet again. The method I used won't allow me to have distinct instances. 10:53
So I want to try an other method : using classes similarily as closures. If that makes any sense.
Here is a mockup : gist.github.com/grondilu/386665ea3...96f6bab244 10:54
Would you mind look at it and tell me if that makes sense to you?
lizmat grondilu: one thing that jnthn taught me (again and again I might say) is that classes are *not* closures 11:03
looking at your gist, all instances returned will be instances of the *same* anonymous class
so there's no difference with calling that class "Foo" and doing "say Foo.new: 13 for ^100" 11:04
SmokeMachine grondilu: for that, maybe you should use MOP. 11:18
m: sub get-class { my $type = Metamodel::ClassHOW.new_type: :name(“UnluckyNumber” ~ ++$); $type.^compose; $type }; say get-class.^name for ^3 11:22
camelia UnluckyNumber1
UnluckyNumber2
UnluckyNumber3
SmokeMachine grondilu: 👆 11:23
grondilu noted 11:58
lizmat still, this does feel like a X-Y solution.. :-) 12:04
grondilu I think I'll try to use parametrized roles again. I just need to accept that the parameter has to be known at compile time. 12:17
lizmat m: role Foo[$a] { method bar() { $a } }; my $b = 42; say Foo[$b].new.bar; 12:19
camelia 42
grondilu using the MOP seems too complicated
lizmat grondilu: ^^ the parameters to a parameterized role don't need to be known at compile time
grondilu well I'm confused then, as that is not what we concluded few days ago. 12:20
lizmat m: role Foo[$a] { method bar() { $a } }; my $b = 42; class Bar is Foo[$b] { }; dd Bae 12:21
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared name:
Bae used at line 1. Did you mean 'Bag', 'Bar'?
lizmat m: role Foo[$a] { method bar() { $a } }; my $b = 42; class Bar is Foo[$b] { }; dd Bar.new.bar
camelia Any
lizmat if you consume a role into a class, it needs to be compile time
m: role Foo[$a] { method bar() { $a } }; BEGIN my $b = 42; class Bar is Foo[$b] { }; dd Bar.new.bar
camelia 42
lizmat but not if you pun a role 12:22
grondilu indeed
japhb .tell grondilu When samuraisam and I worked on Protocol Buffer support, we used the MOP; you'll find it in several places in: github.com/samuraisam/p6-pb 19:13
tellable6 japhb, I'll pass your message to grondilu
ecocode___ hi. how should I define a Type "unit" which can be either of these Str "m", "m2", "m3" ? 22:40
gfldex m: enum Unit <m m1 m2>; my $str = 'm1'; say ::($str) ~~ Unit; 22:44
camelia True
gfldex You can use an enum for that, but a Set might be better.
m: enum Unit (<m m1 m2> Z=> <m m1 m2>); my $str = 'm1'; say $str ~~ Unit; sub foo(Unit() $u) { say $u }; foo('m2'); 22:51
camelia False
m2
gfldex m: enum Unit (<m m1 m2> Z=> <m m1 m2>); my $str = 'm1'; say $str ~~ Unit(); sub foo(Unit() $u) { say $u }; foo('m2'); 22:52
camelia True
m2
gfldex I didn't know that ~~ takes a coersion type. 22:53
ecocode___ how would you use a set instead ?
gfldex I shall query Roast and check for ENODOC tomorrow. 22:54
melezhik . 22:54
gfldex m: constant Unit = Set(<m m2 m3>); say 'm2' ~~ Unit;
camelia False
gfldex m: constant Unit = Set(<m m2 m3>); say 'm2' ∈ Unit;
camelia True
ecocode___ sounds good 22:55
for my usage :)
is there an ascii alternative for ∈ ?
ecocode___ hmmm... Attribute definition of type Set (implicit : by pragma) needs to be marked as required or given an initializer 22:59
can't use the Set in "has Unit $.unit" in a class definition ? 23:00
it works with enum, but then without using strings 23:01