00:28 MasterDuke joined 00:40 teatime joined 00:41 Manifest0 left 03:58 Heptite left
winfredraj m: use P5pack; unpack("l", 46754); 05:07
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Could not find P5pack in: /home/glot/.raku /nix/store/g1bz1z20yh9n8dg7913r68grnkgg3584-rakudo-2024.01/share/perl6/site /nix/store/g1bz1z20yh9n8dg7913r68grnkgg3584-rakudo-2024.01/share/perl6/vendor /nix/store/g1bz1z20yh9n8dg7913r68grnkgg3584-rakudo-2024.01/share/perl6/core
CompUnit::Repository::AbsolutePath<6320783867080> CompUnit::Repository::NQP<6320784284904> CompUnit::Repository::Perl5<6320784284944> at /home/glot/main.raku:1
08:01 Manifest0 joined 08:20 dakkar joined
lizmat winfredraj you can only unpack a Buf/Blob 08:59
10:28 ronald joined 10:37 MasterDuke left 11:26 ronald left
winfredraj figured that out, thanks for the package lizmat, saved me doing a bunch of tedious transforms 13:20
lizmat glad to hear 13:21
winfredraj the reason why I tried that was, was to figure out how to use packages in m:
lizmat you can't, sadly :-( 13:22
winfredraj oh
lizmat only modules that are provided with the core Rakudo 13:32
m: use Test; ok 1
camelia ok 1 -
16:31 dakkar left
winfredraj hello all, is there a way to write multimethod with a where clause based on the calling object, can I for example use something like multi consume(where self!state == 1)? 16:47
antononcube @winfredraj You will most like get a message that that feature is not implemented yet. 16:50
winfredraj oh no, would have made my code really clean 16:52
ab5tract I don’t know about private methods but
Give me a second
antononcube @winfredraj Can you try this? Is it close to what you want? my class Example { has $.state; multi method consume(where self.state == 1) { "State is 1" } multi method consume(where self.state != 1) { "State is not 1" } } my $obj1 = Example.new(state => 1); my $obj2 = Example.new(state => 2); say $obj1.consume; # State is 1 say $obj2.consume; # State is not 1 16:53
I get this message with that code: > Cannot do non-typename cases of type_constraint yet
winfredraj im getting the same thing both with . and ! 16:56
maye we should mention the type as well
antononcube Is this clean enough? my class Example { has $.state; method consume() { given $!state { when 1 { self!consumeOne } default { self!consumeMore } } } method !consumeOne() { "State is 1" } method !consumeMore() { "State is not 1" } } my $obj1 = Example.new(state => 1); my $obj2 = Example.new(state => 2); say 16:57
$obj1.consume; # State is 1
winfredraj just learning the beauty of multiple dispatch so going overboard with it 16:58
ab5tract m: class V { method t() { True }; method v($SELF: $ where $SELF.t.so= “ignored”) { say “check your self” } }; my $v = V.new; $v.v
camelia check your self
ab5tract But it might be useful to look into the underutilized PRE phaser here as well 16:59
winfredraj I am trying to wrap my head around this, what is $SELF:S denote? 17:13
ab5tract Ah, fair enough! 17:16
You can access self as a regular scalar variable by declaring it as the first parameter of a method _behind a single :_ 17:17
$SELF is a common convention but it could be anything
The anonymous variable after the colon is to signal that you don’t care about this value within the method 17:18
winfredraj and the $after :, what does that denote?
lizmat uses \SELF: to get at any container the invocant is living in
winfredraj ah ok $ is dont care , just had to read again once more 17:25
thanks
antononcube @ab5tract Well, I do not see a multi method definition -- can you provide a full write up with at least two multi methods that check an attribute $!state? 17:34
ab5tract No
winfredraj: $ is a bit more than that in fact but in the context of a routine signature it’s a way to attach constraints like type or a where clause 17:37
But it does count as a positional so it becomes a required argument unless you add a default value as I did above 17:38
You will see anonymous variables inside of blocks where their ultimate utility is revealed
m: sub s { say ++$ }; s() xx 5 17:40
camelia 1
2
3
4
5
ab5tract One common use for them in signatures is dispatching based on enum 17:42
Since you don’t really care about that enum inside of the method, you can do ‘multi method m(@actions, TaskType $ where Compile) {…}’ 17:43
winfredraj thanks for the explanation 17:47
antononcube @ab5tract "No" -- Your code then does not answer the original question. Interesting, though... 17:53
ab5tract antononcube:If you weren’t treating me like an AI, you might get better results 18:18
I’m not in the business of producing “full write ups” on demand when I’ve presented the exact core of the question: how to call methods on self from a where clause 18:20
antononcube @ab5tract Ok, your code does show how to call a method with self and where clause. But I doubt it scales. 18:25
ab5tract m: class C { has $!v = “ok”; multi method m($ where $!v eq “ok”) { say “no longer ok”; $!v = “nok” }; multi method m($ where $!v eq “nok”) { say “let’s go back to ok”; $!v = “ok” } }; my $c = C.new; $c.m(“ignored”) xx 5
camelia no longer ok
let’s go back to ok
no longer ok
let’s go back to ok
no longer ok
ab5tract Scales to what?
Present something it doesn’t do
More importantly, try it on your own and see what it _can_ do before treating me like a prompt 18:26
antononcube @ab5tract The last code you provided does I asked earlier. And it fairy different that your first code answer. 18:28
And, yes, I did try both your code before asking you to clarify. 18:29
ab5tract A “full write up” is clarification now? 18:34
Asking for clarification would have been something like, “can I use this with instance variables?”
But why would you ask that when you can literally try it in a minute or less? 18:35
Even so, you would have gotten a friendlier response with that line of asking
antononcube Mean response with working code is fine too. 18:39
And, no I did not figure out how to use your original code answer, that is why asked. 18:40
ab5tract It’s usually helpful to have an example of what isn’t working for someone in order to help them 18:42
winfredraj got the original exmaple working -> "ignored" seems to be important - Thanks all
ab5tract winfredraj: awesome! 18:44
winfredraj or any argument for that matter, ill play around more with it 18:46
librasteve fwiw I like this multi method m(\this: $ where this.v eq “ok”) {...} 18:49
$SELF is a bit too shouty for me
and self is already defined
antononcube @ab5tract "It’s usually helpful to have an example of what isn’t working for someone in order to help them" - It is also seems very helpful to tell someone that their approach is wrong and it does not apply. Then they provide working code. 18:50
ab5tract m: class V { has $!t = False; multi method v($SELF where $!t:) { say “check your self”; $!t = False}; multi method v($SELF where not $!t:) { say “check YOU out!”; $!t = True} }; my $v = V.new; $v.v xx 9 18:53
camelia check YOU out!
check your self
check YOU out!
check your self
check YOU out!
check your self
check YOU out!
check your self
check YOU out!
ab5tract winfredraj: check this out ^^^ 18:54
winfredraj oh cooler
ab5tract antononcube: that only works when it’s true. You still haven’t provided an example of what wasn’t working for you 18:55
I don’t even understand how you can argue that my code didn’t work when it literally 18:57
works here in the chat
the original question said nothing about using instance variables
winfredraj m: class V { has $!t = False; multi method v($SELF where $!t:$just_for_test) { say “check your self”; $!t = False}; multi method v($SELF where not $!t:) { say “check YOU out!”; $!t = True} }; my $v = V.new; $v.v(1) xx 9 18:58
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '$just_for_test' is not declared. Perhaps you forgot a 'sub' if this was intended to be part of a signature? at /home/glot/main.raku:1 ------> = False; multi method v($SELF where $!t:⏏$just_for_test) { say “check your self”;
winfredraj oh just tried your 2nd example with a second parameter, just playing around 18:59
ill play in my repl instead of making the chat untidy 19:00
ab5tract No worries :)
I think the issue there is that $!t is set to False by default but you only added a positional argument to the candidate that needs $!t to be true 19:02
winfredraj: ah, well that's a different issue, but the error above is because the parser needs a whitespace between that single colon and the first variable 19:05
antononcube @ab5stract "I don’t even understand how you can argue that my code didn’t work when it literally" -- where / when did I say that? 19:06
winfredraj got to hit the sack - thanks @antononcube @librasteve @<ab5tract> and @lizmat - goodnight ( or later) 19:09
ab5tract antontoncube: `It is also seems very helpful to tell someone that their approach is wrong and it does not apply. Then they provide working code.` 19:10
that statement implies non-working code
You still haven't shared a single example of something you tried with what I've presented that didn't work 19:11
Let alone something that demonstrates that my "approach is wrong" and inapplicable 19:13
antononcube @ab5tract That was a generic statement, an answer to your generic statement. Note that you are not mentioned in that in statement. 19:25
ab5tract I didn't present a generic statement. I was specifically referring to your approach 19:31
And I am incredulous that you expect me to believe that you didn't intend the same
antononcube @ab5tract Believe whatever you want, but I did not write that your code in not working. 19:36