01:29 Manifest0 left 03:00 kjp left 03:01 kjp joined 03:03 kjp left, kjp joined
rcmlz I have API access - for using Jupyter::Chatbook - but no Plus or Pro account. Will check if I can switch the model to „reasoning“ to find out why I get Raku Code examples on generic CS questions. 04:42
09:05 Manifest0 joined 09:20 dakkar joined
pro1dream hello everybody. I have a question, is it possible to delegate all methods of a role to an attribute in a class? I tried it like this, but it doesn't work: class Foo does Positional { has @.real-list handles *; } my @l = [^5]; my $foo = Foo.new(real-list => @l); say $foo[1]; the documentation says that when I pass Whatever to the trait it should delegate to delegate all methods that the attribute 13:22
can call and: say so @l.WHAT.^can("AT-POS"); prints true. Am I missing something?
lizmat feels like you found a bug in dispatch :-( 13:31
m: liz@M1Mini CLI-Ecosystem % r 'class Foo { has @.real handles * }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo.AT-POS(3)
class Foo { has @.real handles * }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo.AT-POS(3) 13:32
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> liz<HERE>@M1Mini CLI-Ecosystem % r 'class Foo { h
expecting any of:
infix
infix stopper
statement end
statement modifier…
lizmat m: class Foo { has @.real handles * }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo.AT-POS(3)
camelia Index out of range. Is: 3, should be in 0..0
in block <unit> at <tmp> line 1
lizmat so, that does not dispatch to @!real
but this does:
m: class Foo { has @.real handles * }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo.contains(3)
camelia Calling '.contains' on a Array, did you mean '$item (elem) @list'?
True
in block <unit> at <tmp> line 1
lizmat this is probably because: 13:33
m: dd Any.contains(3)
camelia No such method 'contains' for invocant of type 'Any'
in block <unit> at <tmp> line 1
lizmat so it looks like the "handles" applies only to methods that weren't provided already by inheritance 13:34
although the documentation is vague about this functionality: 13:35
"a Whatever (to delegate all methods that the attribute can call), or a HyperWhatever (to delegate all method calls, even ones that will lead to the attribute's FALLBACK method)"
pro1dream maybe raku.land/zef:lizmat/InterceptAllMethods is what you're looking for 13:36
and a use case to peruse: github.com/lizmat/Object-Trampolin...ne.rakumod 13:38
pro1dream aah, makes sense 13:44
yes, the documentation doesn't explicitly talk about this case 13:47
that's really interesting, I'll look into it, thanks!
lizmat so it *could* be a documentation issue
m: class Foo { has @.real handles <AT-POS> }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo.contains(3) 13:48
camelia No such method 'contains' for invocant of type 'Foo'
in block <unit> at <tmp> line 1
lizmat m: class Foo { has @.real handles <AT-POS> }; my @l = ^5; my $foo := Foo.new(real => @l); say $foo[3]
camelia 3
lizmat as you can see, you *can* override specific methods that are already provided
pro1dream oh yes, I forgot to mention, I tried specifying the names of all methods from Positional and then it works 13:52
but I was trying to do it in a way that I didn't have to write all of them every time 13:53
lizmat ah, in that case, define a constant with the method names:\ 13:55
my constant methods = <AT-POS EXISTS-POS>
then specify that constant with the "handles" trait: 13:56
class Foo { has @.real handles methods }
you could put that constant specification in a separate module and export that, for wider usability 13:57
pro1dream that's a good idea, I noticed that I can also introspect a role or class if I need. It won't work in this case and I don't know about the performance but it's nice to know it's possible 14:03
class Foo does Positional { has @.real-list handles(Positional.^methods(:local)); } my @l = [^5]; my $foo = Foo.new(real-list => @l); say $foo.of(); 14:04
the only method in Positional is of but if I have my own role it might work
lizmat as long as the argument you give to "handles" has a compile-time value, you should be ok 14:05
pro1dream understood, thanks for the help! 14:06
lizmat yw 14:08
14:46 librasteve_ joined 17:32 dakkar left