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.
00:50 Kaipei left
sampersand—2B +| +^2B == FF Is there a way to do type assertions, such as asserting `.WHAT` is a type? In essence, i'm trying to construct another instance of a mixed-in type: ``` 02:10
class Foo {
has $.field;
method incr { $?CLASS.new: field => self.field + 1 }
}
my $foo = Foo.new(field => 4) but role {
method field { callwith() * 2 }
};
say $foo;
say $foo.incr;
say $foo.incr.incr;```
Is there a way to do type assertions, such as asserting `.WHAT` is a type? In essence, i'm trying to construct another instance of a mixed-in type: ```
class Foo {
has $.field;
method incr {
$?CLASS.new: field => $!field + 1
# doesn't work:
# .new: field => $!field + 1
}
}
my $foo = Foo.new(field => 3) but role {
method field { callwith() * 2 }
};
say $foo.field; # should return 6
say $foo.incr.field; # should be 8, but is 4```
Is there a way to do type assertions, such as asserting `.WHAT` is a type? In essence, i'm trying to construct another instance of a mixed-in type: ```
class Foo {
02:16 razetime joined
guifa_ .WHAT should produce a type object always, AFAIK. It's not even a real method, and is compiler controlled. I'm not sure I see how it would benefit what you're trying to do 02:53
your last code works fine for me: 02:56
m: class A { has $.b; method i { self.new: b => $!b + 1} }; my $c = A.new(:3b) but role { method b { callsame() * 2 } }; say $c.b; say $c.i.b;
camelia 6
8
guifa_ the reason $?CLASS doesn't work is that it will refer to a fresh unmixed class, so the role isn't applied 02:57
self.new (or even self.WHAT.new if you feel dirty acting on an definite object) will keep the mix 02:58
sampersand—2B +| +^2B == FF cool thanks 03:11
that works :-) 03:15
What's the purpose of `my method foo`? why have the `my`? Likewise for `submethod foo` 03:24
04:00 razetime left 04:35 razetime joined 04:37 Ebudae joined 04:41 Heptite left 04:42 Ebudae left 05:13 Manifest0 left, gfldex left, human_blip left, gfldex joined, Manifest0 joined 05:16 human_blip joined
Nemokosch docs.raku.org/language/objects#ind...Submethods 05:55
06:59 kueppo joined 07:47 dakkar joined 08:01 razetime left 08:25 kueppo left 08:26 razetime joined 09:05 razetime left, razetime joined 10:00 Kaiepi joined 10:05 razetime left 10:27 razetime joined 12:07 discord-raku-bot left, discord-raku-bot joined 12:29 jgaz joined 13:04 discord-raku-bot left, discord-raku-bot joined 13:06 kueppo joined 13:32 discord-raku-bot left 13:33 discord-raku-bot joined 13:37 discord-raku-bot left, discord-raku-bot joined
lizmat And yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2022/10/17/2022-...p-no-fear/ 14:10
14:35 Heptite joined 16:35 dakkar left 18:16 razetime left 19:20 Kaiepi left, Kaiepi joined 19:38 Kaiepi left, Kaiepi joined 19:43 Kaiepi left 20:05 Kaiepi joined 22:58 Heptite left, Heptite joined 23:00 jgaz left