25 Jul 2024
greenfork Basically I want to do something like this Surface::Fire.draw 11:24
I think this is the closest code paste.sr.ht/~greenfork/f10f0f0670f...cf3b6b3e76 11:25
I also posted on stackoverflow this question, will answer it myself after figuring out the optimal solution I think stackoverflow.com/questions/787930...or-an-enum
lizmat that works, so what's wrong with it? 11:26
greenfork Nothing wrong, I just don't like the way it is written 11:27
My other classes are like class A { method draw { ... } }, so they are all called like $a.draw, I wanted to have a similar interface for the enum 11:28
But I think that it requires wrapping it in a class
[Coke] you can pun a class into that role. 12:57
m: role DrawSurface { method draw($a) { say $a } }; my $b = DrawSurface.new; $b.a("hi") 12:58
camelia No such method 'a' for invocant of type 'DrawSurface'
in block <unit> at <tmp> line 1
[Coke] m: role DrawSurface { method draw($a) { say $a } }; my $b = DrawSurface.new; $b.draw("hi") 12:59
camelia hi
[Coke] so if you want an instance var, you can still make one, even if it's a role not a class.
antononcube I think we can also make a class that does the role Enumeration? (I am not in front a computer, I am just reading the enum documentation on my iPad.) 13:05
[Coke] Yes, you can do it manually too of course. 13:41
m: role DrawSurface { method draw($a) { say $a } }; class C does DrawSurface {}; my $b = C.new; $b.draw("hi") 13:42
camelia hi
[Coke] you basically get an anonymous C in the first example.
greenfork: hope that helps. 13:54
greenfork [Coke]: this is interesting, thank you for tagggin me! 13:56
xinming Hi, Is it possible that we use PSGI in Cro? 18:57
jdv why? 19:00
it was talked about a bunch years ago, psgi and raku that is. 19:01
what is justification?
antononcube Is "PSGI" in Raku going to be called "RSGI"? 19:02
jdv afaik, the general psgi/raku thing went nowhere 19:03
xinming Ok, I just check my old test utility written in perl, I have TODO to say upgrade to PSGI, which reminds me about PSGI thing in raku support. :-) 19:40
antononcube @ximming Do it, ximming! Do it! 20:08
26 Jul 2024
patrickb I seem to recall there was a (now unmaintained PSGI stack for Raku. 05:13
antononcube Maybe someone should do a design or motivational document for "Raku SGI" similar to this one: metacpan.org/dist/PSGI/view/PSGI/FAQ.pod 12:41
ugexe raku.land/cpan:HANENKAMP/Smack was an experiment with something more raku-specific 12:47
antononcube 👍 12:55
Xliff_ \o 13:55
Good morning! I'm trying to port some Javascript that wants to use a Map with object keys. I thought this would work, but it doesn't...
m: class A { }; my $c = Hash[A, Mu].new; my $aa := A.new; my $bb = A.new; $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.^name ).gist.say
camelia Type check failed in assignment to ; expected A but got Int (1)
in block <unit> at <tmp> line 1
Xliff_ m: class A { }; my $c = Hash[A, Mu].new; my $aa = A.new; my $bb = A.new; $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.^name ).gist.say
camelia Type check failed in assignment to ; expected A but got Int (1)
in block <unit> at <tmp> line 1
Xliff_ I'm a little concerned about the "assignment to ;". Can someone help? 13:56
Odd... this does! 13:58
m: class A { has $.a }; my $c = Hash[Mu, Mu].new; my $aa := A.new( a => 42 ); my $bb = A.new( a => 23 ); $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.a ).gist.say
camelia {A.new(a => 42) => 1, A.new(a => 23) => 2}
(23 42)
ugexe m: class A { }; my %c{A}; my $aa := A.new; my $bb = A.new; %c{$aa} = 1; %c{$bb} = 2; %c.gist.say; %c.keys.map( *.^name ).gist.say 16:27
camelia {A.new => 2, A.new => 1}
(A A)
ugexe m: class A { }; my $c = Hash[Mu, A].new; my $aa := A.new; my $bb = A.new; $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.^name ).gist.say; $c{1} = 1 16:28
camelia {A.new => 2, A.new => 1}
Type check failed in binding to parameter 'key'; expected A but got Int (1)
in block <unit> at <tmp> line 1

(A A)
ugexe m: raku -e 'class A { }; my $c = Hash[Mu, A].new; my $aa := A.new; my $bb = A.new; $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.^name ).gist.say 16:29
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> raku -e⏏ 'class A { }; my $c = Hash[Mu, A].new;
expecting any of:
infix
infix stopper
postfix
statement …
ugexe m: class A { }; my $c = Hash[Mu, A].new; my $aa := A.new; my $bb = A.new; $c{$aa} = 1; $c{$bb} = 2; $c.gist.say; $c.keys.map( *.^name ).gist.say
camelia {A.new => 2, A.new => 1}
(A A)
ugexe anyway you can do `my Hash %c{A}` or you need to reverse the parameters to Hash i.e. Hash[Mu, A] instead of Hash[A, Mu]
Xliff_ ugexe: Thanks... so it has to be '$' sigil'd and Hash[<val>, <key>] ? 17:11
ugexe my %c{A}; %c{$a} = 1; or my $c = Hash[valType, keyType].new 18:24