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:16
jgaz left
00:28
deoac left
02:20
Manifest0 left
02:28
Ebudae joined
02:29
Heptite left
03:08
Ebudae is now known as Heptite
04:04
kjp left
04:05
saint- left
04:07
kjp joined
04:50
rf left
05:32
Heptite left
08:39
QhpAptyj9hj0RQwM joined
10:28
Manifest0 joined
11:14
frost joined
|
|||
snonux | Hi there, how can I call the same method of a parent class? E.g. in: class Foo { method test { <Foo.test>.say; } }; class Bar is Foo { method test { ALSO-CALL-test-FROM-FOO-HERE(); <Bar.test>.say; } }; Bar.new.test; | 11:21 | |
Was looking at docs.raku.org/language/classtut#Inheritance | 11:22 | ||
lizmat | docs.raku.org/language/functions#Re-dispatching is what you probably want to see | 11:23 | |
Nemokosch | hi, from what I learned, this is a more complex topic than it sounds at first - there are several methods a call could fall back to, including the possibly multiple ancestor classes and mixins. If you are confident what your parent class is, a simple way would be to do something like self.Foo::test | 11:24 | |
snonux | @lizmat, ahh, yes! callsame() works, thanks! | ||
Nemokosch | callsame is supposedly the clean solution but it's really for much more than a method chain - it's a mixture of method resolution and multiple-dispatch resolution (based on parameters) | 11:25 | |
lizmat | if it works, it works, no ? | 11:26 | |
snonux | thanks Nemokosch, yes, in my case, i only have one parent class and no roles mixed in. | 11:27 | |
Nice, that it's actually 'callsame' to be called - which is pretty close to the question I asked 'how can I CALL the SAME method'. What you write is what you get :-) | 11:31 | ||
lizmat | snonux: indeed, that was one of TimToady's design goals | 11:32 | |
Nemokosch | yes, it works - I'm just saying, don't be surprised that you get a bit more than what you think you are asking for | 11:33 | |
there can be times when that's exactly what you desire and times when it won't (easily) do the trick | 11:34 | ||
el gatito (** advocate) | self.^mro[1].^method_table<test>(self) will always call the superclass method 😎 | 12:19 | |
Nemokosch | 😂 | 12:27 | |
lizmat | Note that this may depend on Implementation details and may stop working at any time | 12:31 | |
and as such not really beginner's stuff | 12:33 | ||
12:39
QhpAptyj9hj0RQwM left
|
|||
el gatito (** advocate) | the metamodel is implementation detail? | 12:54 | |
12:59
QhpAptyj9hj0RQwM joined
|
|||
lizmat | well, it is a grey area: there are no spectests for method_table, and no Rakudo tests for it either | 12:59 | |
even though it is documented... so there's that | |||
and we recently had some nasty module regressions when some aspect of the metamodel needed changing (an extra parameter to a method) | 13:03 | ||
el gatito (** advocate) | there are cases where redispatching does not give expected behavior like this glot.io/snippets/gidp0msau6 | 13:15 | |
in those cases you have no choice but this | 13:16 | ||
actually you have another choice of self.B.f | 13:18 | ||
but still | |||
lizmat | you mean self.B::f ? | 13:23 | |
but yes, *that* would be preferable way of doing and *that* is sure to remain supported | |||
el gatito (** advocate) | then if i want to call it, do i have to include self in the argument? | 13:29 | |
like self.B::f(self: #(...))` | 13:30 | ||
lizmat | not in that case, as it is still considered to be a method call | 13:33 | |
m: class A { method b($a) { dd $a } }; A.A::b(42) | 13:34 | ||
camelia | 42 | ||
el gatito (** advocate) | it is sad when raku’s 3 ways of calling superclass method is either: - not really super (redispatch) - implementation dependent magic - just spelling out the class name (explicit is better than implicit i guess?) | 13:43 | |
Nemokosch | thank heavens that I didn't have to say that... | 13:44 | |
you might have social credits left to be taken with good faith | |||
lizmat | why is redispatch not really super ? | 13:48 | |
el gatito (** advocate) | this | 13:49 | |
lizmat | m: class A { method a() { dd } }; class B is A { method a() { dd; nextsame } }; B.a # this ? | 13:51 | |
camelia | method a(B: *%_) method a(A: *%_) |
||
lizmat | m: class A { method a() { dd } }; class B is A { method a() { callsame; dd } }; B.a # this ? | ||
camelia | method a(A: *%_) method a(B: *%_) |
||
el gatito (** advocate) | have you read the code | 13:52 | |
glot.io/snippets/gidp0msau6 | |||
lizmat is looking | 13:59 | ||
Nemokosch | the other thing is that I kept asking about and never got a clear answer is: is there a standard, non-metamodel way to get hold of a method, in the first place? | 14:05 | |
or only find_method, lookup sort of stuff? | |||
lizmat | so, a part of the complexity in that example is that A_ is a subclass of A | ||
given that, I think the dispatch is correct | 14:06 | ||
now, there may be reasons for having an A_ inheriting from A, but it feels to me that using roles may be a better solution | 14:07 | ||
now, the interesting part is when A_ is *not* a subclass of A | |||
el gatito (** advocate) | > given that, I think the dispatch is correct yes, but it is not the behavior given by the mro version | ||
the mro behavior is the expected one | |||
lizmat | in that case, the calls are: C: hi A_, B: hi A_, B: hi A_ | ||
el gatito (** advocate) | yes | 14:08 | |
lizmat | which I think is actually an error, having B: hi A_ in there twice | ||
so if you could make an issue for that, please | |||
el gatito (** advocate) | but the redispatch is C: hi A_ B: hi A_ C: hi A B: hi A | ||
lizmat | as to Nemokosch's question | 14:09 | |
snonux | i see, you people are still ongoing with the dispatch :D | ||
el gatito (** advocate) | isn't that D: hi A_ B: hi A_ B: hi A | ||
lizmat | snonux: we know there are some long standing issues with dispatch, but fixing them is *hard* and may affect performance drastically | 14:10 | |
as just about everyting in Raku is dispatch | |||
el gatito the only thing I changed in the code, was remove the "is A" | 14:11 | ||
el gatito (** advocate) | about that idk why lol | ||
also dispatch isn't the problem in this case the problem is raku doesn't have a convenient way to truly delegate method calls to the superclass no super or anything even tho that should be pretty easy to implement | 14:16 | ||
lizmat | well, you're welcome to create a PR or a module :-) | 14:17 | |
14:51
ab5tract left
15:20
frost left
16:04
Heptite joined
16:20
yjh left
16:42
QhpAptyj9hj0RQwM left
19:05
QhpAptyj9hj0RQwM joined
19:43
QhpAptyj9hj0RQwM left,
QhpAptyj9hj0RQwM joined
20:45
QhpAptyj9hj0RQwM left
|
|||
Yeuph | Would someone be able to give me some pointers? I'm trying to figure out how to get a class to accept sets What would that look like? I've been tinkering for a while and documentation is limited | 20:58 | |
like `class Sets { has [what goes here?] } And how to add that to the class | 20:59 | ||
Nemokosch | has is for creating attributes and properties - so far so good? | 21:01 | |
Yeuph | assuming that SetHash is included in attributes and properties, yes | ||
(also yes if not; which would mean that is the route of my issue) | 21:02 | ||
Nemokosch | I mean, you know what you are going for here? To put a SetHash inside a class so that the class can contain it for whatever purpose | 21:03 | |
well, the object instances can | |||
Yeuph | I do know what I want to make, I just haven't used Raku in about a year at this point and can't claim to know the language well. I'm coming from C++ | 21:04 | |
which probably has near-zero translation value | |||
Nemokosch | so this is like private/public: field declaration | ||
Yeuph | ok | ||
Nemokosch | is this what you want to achieve? | ||
Yeuph | public, yes | ||
Nemokosch | okay, so you can do has SetHash $.foobar | 21:05 | |
you don't need to declare the type, sometimes it's actually better to avoid it | |||
but this is the syntax | |||
Yeuph | alright, then declaring that set in the class is done how? `class Set { has SetHash $.foobar } my &thing = Set.new(foobar => [how are we approaching this?]) | 21:08 | |
Nemokosch | this will create a private attribute $!foobar and an accessor method foobar to it | ||
first off, I wouldn't overload the name Set if I were you, it might bite back somewhere | 21:09 | ||
Yeuph | yeah my names are separate in what I'm actually writing | ||
(which isn't much at this point and the code isn't worth posting) | |||
Nemokosch | second, storing it into a &variable (so a Callable) probably won't work, unless you make your class implement Callable | ||
and I doubt that's your intention anyway | 21:10 | ||
Yeuph | I should probably breeze through some of the Raku course stuff for a few hours | ||
I'm gonna do that. I was hoping I'd remember stuff/be able to just figure it out. I need to just spend a few hours going over the language | 21:11 | ||
what's the best documentation/course now? | 21:12 | ||
Nemokosch | and third, actually, I'm not sure what you can feed in there as the value of the named argument; my guess would be, anything that can be on the rhs of an assignment of a variable like my SetHash $foobar | ||
so typically something coerced into SetHash | |||
Yeuph | ok | 21:13 | |
is there a website for Comma error messages? | 21:14 | ||
Nemokosch | I'm afraid you'd need to ask people with Comma affiliations for that | 21:15 | |
Yeuph | ok thanks for your time | ||
Nemokosch | for classes, I'd still say this docs.raku.org/language/classtut | ||
shmup | also Yeuph idk if you've used the search feature on the docs, but it's a pretty nice breakdown of things and i've been using it a lot: i.imgur.com/VmDYyCA.png | 21:18 | |
Nemokosch | the search can usually make an "educated guess" where a certain topic is covered 😛 | 21:19 | |
shmup | well i actually would have searched for this which is even better results :P i.imgur.com/kUAOqZI.png | 21:20 | |
ive also been using chatgpt as a feedback loop on asking questions about syntax i see in code, and it generally helps me with looking the next thing i wanna look up in some doc/etc | 21:21 | ||
it really does have parallels to a question you might drop in #irc if the outcome (often) is giving you a thing to specific thing/direction to research | 21:23 | ||
i am not able to type sentences rn :) | 21:24 | ||
Yeuph | alright I'll play with this as well | 21:25 | |
22:02
rf joined
22:16
QhpAptyj9hj0RQwM joined
22:56
QhpAptyj9hj0RQwM left
|