This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
02:08 Manifest0 left 04:47 rf left 06:13 Heptite left 10:11 ab5tract joined 10:21 Manifest0 joined 10:32 frost joined 12:14 Heptite joined 12:46 discord-raku-bot left, discord-raku-bot joined 15:28 yjh joined
yjh Should the following work? 15:33
role R[::T] { method m ( T @a ) { } }
class C does R[Str] { }
my Str @a = 'a';
C.new.m: @a;
I'm getting "Internal error: inconsistent bind result"
ab5tract Hmm... 15:35
yjh: yes, that appears to be a bug 15:37
yjh: it appars to work with 15:40
role R[::T] { method m ( ::T @a ) { } }
Nemokosch well, wait. @a is a one-element array with 'a' in it, right? 15:41
ab5tract m: role R[::T] { method m ( ::T @a ) { dd @a } }; class C does R[Str] {}; my Str @a = 'a'; C.new.m: @a
camelia Array[Str @a = Array[Str].new("a")
el gatito (** advocate) yes
Nemokosch do "we" know if this is supposed to work? 15:43
ab5tract yjh: So I'm no longer sure it's a bug 15:44
Nemokosch thinking of ::?CLASS, for example
:: seems kinda like a sigil in these cases
el gatito (** advocate) type variable sigil 15:45
Nemokosch where did you find it?
el gatito (** advocate) it is inferred 15:46
Nemokosch okay... so where do you infer this from? 😛
el gatito (** advocate) the fact that ::T declares a type variable 15:47
Nemokosch okay... where did you find that? 👀
ab5tract I just gave an example of it. But I think the point here is not whether it is a sigil, exactly. It seems to be an indicator of an explicit package 15:49
s/explicit/implicit/
Nemokosch no, my question is: where can one read more about it?
ab5tract yjh: I hope my solution helps
el gatito (** advocate) you don’t know type captures? docs.raku.org/type/Signature#Type_captures 15:51
Nemokosch I didn't know they were called that, that's for sure
el gatito (** advocate) also notice the last argument of the function in the example 15:52
Nemokosch > # $p1 and $p2 are of the same type T, that we don't know yet 15:53
the code example suggests that ::T and T would behave the same way, no?
el gatito (** advocate) m:perl sub type(::T) { return T } say type 42; 15:54
Raku eval (Int)
el gatito (** advocate) yeah
m:perl sub type(::T) { return ::T } say type 42;
Raku eval (Int)
Nemokosch what about T in the signature? 15:58
m: sub type(T) { return T } say type 42;
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Invalid typename 'T' in parameter declaration. at /home/glot/main.raku:1 ------> sub type(T⏏) {
Nemokosch that's one down I guess.. 15:59
ab5tract m: role R[::T] { method m ( ::T @a, T @b ) { dd @b } }; class C does R[Str] {}; my Str @a = 'a'; C.new.m: @a, @a
camelia Internal error: inconsistent bind result
in method m at <tmp> line 1
in block <unit> at <tmp> line 1
Nemokosch m: sub type(T $foo) { return $foo } say type 42;
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Invalid typename 'T' in parameter declaration. at /home/glot/main.raku:1 ------> sub type(T⏏ $foo) {
ab5tract m: role R[::T] { method m ( ::T @a, ::T @b ) { dd @b } }; class C does R[Str] {}; my Str @a = 'a'; C.new.m: @a, @a
camelia ===SORRY!=== Error while compiling <tmp>
Redeclaration of symbol 'T'.
at <tmp>:1
------> role R[::T] { method m ( ::T @a, ::T⏏ @b ) { dd @b } }; class C does R[Str] {
Nemokosch how could it work in their example?
el gatito (** advocate) bruh 16:01
cdn.discordapp.com/attachments/768...G_4678.png
Nemokosch okay okay, wait xD
so it seems that ::T is like a declaration on its own
and once you do it, you are allowed to write just T
> role R[::T] { method m ( T @a ) { } } 16:02
but then this should be right, I'd say?
could you link this part? I can't comprehend it 16:08
el gatito (** advocate) docs.raku.org/type/Signature#Argument_aliases 16:09
Nemokosch thankies 16:11
el gatito (** advocate) why does raku feel like a minefield of surprising behavior 😭 16:13
ab5tract el gatito: I know how you feel. I think what we are experiencing here is a bug 16:23
because as Nemokosch points out, once you declare via ::T, you should be able to use 'T' by itself. 16:24
lizmat agreed 16:25
ab5tract unfortunately you can't just defer to Raku's type checking one layer down, a la: 16:26
el gatito (** advocate) im actually referring to the slipping behavior of Hash
ab5tract m: role R[::T] { method m ( @a, @b ) { my ::T @c = @a, @b; dd @c } }; class C does R[Str] {}; my @a = "a"; my @b = "b"; C.new.m: @a, @b
camelia No such method 'instantiate_generic' for invocant of type 'Array[T]'
in method m at <tmp> line 1
in block <unit> at <tmp> line 1
Nemokosch m: class C { has $.x; has $.y; has @.z }; my %h = <x y z> Z=> (5, 20, [1,2]); say C.new(|%h); 16:27
Raku eval C.new(x => 5, y => 20, z => [[1, 2],])
Nemokosch what if we use a List instead of an Array?
m: class C { has $.x; has $.y; has @.z }; my %h = <x y z> Z=> (5, 20, (1,2)); say C.new(|%h);
Raku eval C.new(x => 5, y => 20, z => [(1, 2),])
Nemokosch still pushed into an Array
because %h<z> is $(1,2), I think 16:28
but it also doesn't seem feasible to just downright drop all containers from slips... 16:34
18:36 saint- joined 18:39 jgaz joined 20:09 rf joined 20:51 rf left, rf_ joined 21:22 rf_ left 21:23 jgaz left, rf joined 21:32 deoac joined
deoac Given 21:36
[3] > my %a = <a 1 b 1 c 2>
{a => 1, b => 1, c => 2}
How would I create the Hash/Map: {1 => (a b), 2 => c} ?
Neither .invert() or .antipairs() does the trick.
21:46 jgaz joined 22:00 frost left 22:05 guifa joined 22:08 guifa_ left
MasterDuke deoac: checkout .classify() or .categorize(), they might get you closer 22:14
Nemokosch Sadly invert seems to be the opposite - unwrap rather than wrap 22:16
Classify is a good idea
rf m: <a 1 b 1 c 2>.classify(*.value)>>.key; 22:18
camelia No such method 'value' for invocant of type 'Str'. Did you mean
'values'?
in block <unit> at <tmp> line 1
rf m: Map.new(<a 1 b 1 c 2>).classify(*.value)>>.key;
camelia ( no output )
rf m: say Map.new(<a 1 b 1 c 2>).classify(*.value)>>.key;
camelia {1 => [a b], 2 => [c]}
rf Wish I could leave out the .key 22:20
Maybe a reduce or produce for this
Nemokosch m: <a 1 b 1 c 2>.pairup.classify(*.value, as => *.key).say
Raku eval {1 => [a b], 2 => [c]}
Nemokosch Well, getting closer.. 22:21
rf Nice, didn't know about the as
m: %(<a 1 b 1 c 2>).classify(*.value, as => *.key).say;
camelia {1 => [a b], 2 => [c]}
rf m: %<a 1 b 1 c 2>.classify(*.value, as => *.key).say; 22:22
camelia Use of Nil in string context
{(Any) => []}
in block <unit> at <tmp> line 1
Use of Nil in string context
in block <unit> at <tmp> line 1
Use of Nil in string context
in block <unit> at <tmp> line 1
Nemokosch It's probably an anonymous state variable 22:23
rf I think my second last one is the best so far, thanks for the note on "as" Nemo
22:27 rf left 22:28 rf joined
deoac Thanks Nemokosch & rf.  I've never used classify, glad to have the opportunity 22:40