🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
wayland76 Hi all. I have a .new method, and it has called "callwith" to create the object. In the code that comes after the "callwith", it's still telling me that I can't do things on a partially-constructed object. How do I let raku know that this object should be considered fully-constructed? 00:24
wayland76 (I'm trying to make something that acts like TWEAK, but after the object construction has been completed) 00:37
timo i think if you use what's returned from one of the "new" methods you should be able to do normal stuff with it, can you share some code? 01:32
m: class Yours { has $.foo is rw; method frob { $.foo = 99 }; }; class Mine is Yours { method new { my $res = callwith(:foo(99)); $res.frob; say $res } }; say Mine.new(); 01:34
camelia Mine.new(foo => 99)
True
timo wayland76: is your code anything like this? 01:35
wayland76 timo: gist.github.com/wayland/7899d75548...63961e59fc 04:40
Line 38 is where the problem is. 04:42
If there's already a module that does something like this, I'd be happy to know about it :) 04:43
ab5tract You are still inside the new method though.. 08:39
ab5tract That might be enough to trigger the partially constructed error 08:42
lizmat wayland76: looks like you forgot to add "self" on line 17 > 08:44
?
my $this = callwith(self, |@positional, |%named); 08:45
methods always expect the first argument to be the invocant, even if it is a type object 08:46
wayland76 lizmat: Thanks! Even with that fixed, though, I get the same error. 09:32
ab5tract: Yes, I suspected that was the problem. I'm asking if there's a way to turn it off at a certain point. I'd like to turn it off before the POST-TWEAK methods get called. 09:34
lizmat with RakuAST I get: Cannot look up attributes in a A type object. Did you forget a '.new'? 09:35
on line 36
shouldn't line 22 be: $this.POST-TWEAK(); 09:37
??
also: what are you trying to achieve in lines 31/32 ? 09:39
if you do't want accessors (from the comment: "not public"), define with: has Str $!object-name ? 09:40
also if $!object-slug is supposed to be "not public", how are you expect $.object-slug to be working? 09:41
wayland76 Line 36 should be a submethod. Regarding line 22, I'd like to call all the POST-TWEAK methods, which is why I'm using $type, but I'm concerned it might not call it with the object as the invocant. 09:46
Please ignore the "not public" comments. They're left over from when I copy-pasted the code. I was drawing a distinction between "public" and "protected", which is I think not a distinction supported by Raku. 09:48
Also, the line numbers you're using are not the same as the ones I'm seeing for some reason. It took me a while, but everything you said makes a lot more sense if I add 2 to each line number you mentioned. Weird :) . 09:50
lizmat ah, I removed the hash bang oops 09:51
wayland76 Right. Well, I just updated the gist :) 09:52
lizmat line 23: for $type.can('POST-TWEAK') -> &method {
method($this);
}
appears to make it do what you want in RakUASR 09:53
T 09:54
actually, I don't think you need to run the ^mro
the .can already gives you a list of candidates
perhaps a for $type.can('POST-TWEAK').reverse to get the order you want ? 09:55
changing line 52 to: say self.object-slug; also fixes it on the legacy grammar 09:56
wayland76 I've upgraded last week -- I'm now on January's raku
OK, that's better. When was/will RakuAST be released? 09:57
lizmat as soon as it's ready
wayland76 OK, but are we thinking months or years, or partway in between? 09:58
(won't hold you to it :) )
lizmat I'm hoping for a push the coming months, for a late 2024 / early 2025 release 09:59
wayland76 OK, that's the kind of info I was looking for. Thanks! :) 10:00
lizmat I think this is more or less what you wanted: gist.github.com/lizmat/c123c39edf1...5fae45cb3f 10:06
wayland76 you left out the "self" on the callwith that you recommended. 10:16
...correctly, it seems. 10:18
lizmat yeah... callwith is smart enough it's being called from a method 10:23
*to know
wayland76 That looks good though -- thanks for the improvements :) 10:25
lizmat you're welcome :-)
antononcube It seems to me that a new answer here has to be posted: stackoverflow.com/q/47941500/14163984 13:59
... And probably rename the question as "Using a hash with object keys in Raku". 14:00
tbrowder note not too early for Raku Advent 2024. i’m gonna take 1 dec when i get home. title: “Santa’s Print Shop” 16:40
ab5tract tbrowder++ 18:43
Geth__ advent: tbrowder++ created pull request #112:
Add new directory for year 2024
18:58
advent/main: 8afbf0c1cd | (Tom Browder)++ | 2 files
Add new directory for year 2024

Also add my name and article title
18:59
advent/main: 3f6d73df61 | (Tom Browder)++ (committed using GitHub Web editor) | 2 files
Merge pull request #112 from tbrowder/main

Add new directory for year 2024
ab5tract Well this took a bit of time: github.com/ab5tract/comma-plugin/c...4e0a781454 19:57
antononcube: next time you have any slowdown, this will let you disable any or all of the inspections (formerly annotations) 19:58