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.
02:08 teatwo left 02:32 teatime joined 05:02 teatime left, ab5tract left, deadmarshal_ left, sivoais left, lizmat left 05:03 MasterDuke joined, camelia joined, hexology joined, sjn joined, guifa joined, RakuIRCLogger joined, gfldex joined, mjgardner joined, SmokeMachine joined, KOTP joined, snonux joined, discord-raku-bot joined, human-blip joined, tbrowder__ joined 05:04 RakuIRCLogger left 08:10 dakkar joined 08:21 teatwo joined 08:24 teatime left 09:35 Manifest0 joined, Manifest0 left 09:45 Manifest0 joined 10:04 Manifest0 left 10:36 Manifest0 joined 13:10 lizmat_ joined 13:13 lizmat left 13:20 lizmat_ left, lizmat joined 13:49 destroycomputers left 13:50 destroycomputers joined 14:00 nicole left, nicole joined 14:44 jgaz joined
Tirifto_ lizmat & al., hello again and sorry for the delay! Going back to object-specific-method question, I have now put together a file detailing what exactly I want to do, together with three solutions that sort of work, but carry some drawbacks. 16:26
Here’s a link: tirifto.xwx.moe/d/methods.raku
Sorry if it’s a tad verbose, but it’s the best I could think of. It’s not so much that I can’t find a way of doing what I want, but that I’m trying to find a relatively simple way of doing it, while learning if Raku has any features that support this kind of use, and taking advantage of them. 16:29
lizmat, you specifically asked what I tried when mixing in roles into objects, which is shown in Example 3. 16:31
lizmat I'll look at it later today, am in the middle of something that needs my full attention :-) 16:32
16:37 dakkar left
antononcube @Trifto Yeah, lizmat is upto something that needs max, non-split, part-icipation. 16:39
Tirifto_ Thank you very much! c: 16:43
@antononcube … are those raku puns? :P 16:44
antononcube @Trifto There is a discussion in the "main" IRC channel about using a positional or named argument for the function/method split. Some of the discussed argument names are ":upto", ":max-parts", etc. 16:48
Tirifto_ Oh! 16:51
Well done in that case. 🤭 16:52
antononcube Yeah! I should restrain myself posting puns, but, well, sometimes is way too easy and "natural" to do... 16:55
nemokosch this is why you are banned from doing Python presentations 16:56
lizmat I guess Raku is one of the few languages in the world that has a "pun" meta-method :-) 16:57
and even has a concept of "auto-punning" :-) docs.raku.org/language/typesystem#Auto-punning 16:58
nemokosch by the way 17:13
is there a way to forbid the addition of new multi candidates?
lizmat not in core, I don't think 17:16
nemokosch class C { has Routine $.m; method m(Int $i) { $!m.($i) } } 17:18
this is definitely a clever solution, I don't know if it's actually accounted for
hm, as long as somebody doesn't assume that m is a setter, I think it's good 17:22
antononcube That is why I just use(d) callable attributes. 17:23
See, for example, "FunctionalParsers". 17:24
nemokosch anyway, we have an answer basically, then 17:34
you can't forbid new candidates from being added, that's a definite limitation 17:35
gfldex m: class SomeType { }; say SomeType.clone =:= SomeType; 17:38
camelia True
gfldex m: sub foo { 'role R {}'.EVAL }; say foo() =:= foo(); 17:40
camelia False
gfldex :)
m: role R {}; R.^add_method(my method m {}); 17:41
camelia No such method 'add_method' for invocant of type
'Perl6::Metamodel::ParametricRoleGroupHOW'
in block <unit> at <tmp> line 1
gfldex Tirifto_: Do all the objects need to be of the same ClassHOW-type? 17:52
17:56 ab5tract left
Tirifto_ gfldex, I’ll try and answer that as soon as I manage to understand what ClassHOW is and how it relates to the matter at hand! (I’m looking at the documentation now, but it looks like it might take a while. xP) 18:11
nemokosch It's metamodel wizardry 18:12
gfldex Tirifto_: There are differenct "sources" for types. Like `class`, `role`, `enum` and a few more. That a type-check succeeds does not necessarily mean they are the same `class`. 18:13
nemokosch Weren't you the one who advocated for only doing spectested, "pure" Raku code? 18:15
Tirifto_ Well, going off just that… they ought to be de-facto the same class, but I suppose it’s not important to me how Raku handles that internally. It also shouldn’t be a problem if they are different classes but share a superclass. (Which is sort of done in example 2, but again, feels a bit weird there.) 18:16
At the moment, I don’t really comprehend what metamodels and metaclasses even are. I’ve read about them before, but I might have to do that a few more times before the idea can sit in my head comfortably. cx 18:18
nemokosch that's fair enough
if you know the DOM in the browsers, the metamodel is a bit like a DOM but for data structures in your Raku code 18:20
Tirifto_ @nemokosch So not an interface to access and modify objects (which is, in a way, provided by classes), but rather an interface to access and modify classes in a comparable manner? 18:28
nemokosch Yes 18:29
From the metamodel point of view, a class definition is just some code that can build an object - the object that will represent the defined class 18:30
You may ask, if it's just an object, what (meta)class does it belong to? And this is where we get to ClassHOW 18:31
It's the common class that represents all the defined classes in the metamodel 18:32
m: class Foo {}; dd Foo.HOW; dd Foo.HOW.^mro 18:34
Raku eval Perl6::Metamodel::ClassHOW.new (Perl6::Metamodel::ClassHOW, Any, Mu)
nemokosch Foo is represented by an instance of ClassHOW
And nevermind the other line lol, that was a thinko on my side 18:35
I rather wanted to traverse this meta-chain than the inheritance chain 18:36
gfldex Tirifto_: gist.github.com/gfldex/207374ad35e...fdeacbcd9a 18:39
please note that the invocant has to match
Tirifto_ Hmmm… so is the ordinary type system (Mu ← Any ← … ← Int) regarded as the ‘model’, for there to be a ‘metamodel’ about that model…?
nemokosch Kind of 18:40
It's not about types of data anymore, rather the different structures that can define data. Class, Role, Subset, Package, and so on 18:41
gfldex type-objects know how to construct instances and Metamodel-objects know how to construct type-objects. 18:42
And the VM knows how to construct "bare"-objects. Those are used to construct Metamodel-objects.
gfldex .oO( At the beginning there was a "typedef". ) 18:43
nemokosch Ultimately, if you keep chaining .HOW on an object, you will hit KnowHOW which is the root of this construction hierarchy 18:44
Tirifto_ I asked Raku HOW WHAT? And apparently the answer is (ClassHOW). 🙃 18:48
nemokosch WHAT gives you the type object, HOW gives you the associated meta-object (of course that's the very same object for all instances and the type object as well) 18:50
gfldex Rakudo tries to hide VM-level constructs and recursion is a good way to stop the nosy to get to the bottom of things. 18:51
nemokosch The thing is, it's controversial the least to say, to teach these things for other purposes than Rakudo development
They weren't meant to be public interfaces, not to this extent at least 18:52
Tirifto_ Ah, right… I suppose I need to find the right words or ideas to fill in the question ‘HOW’ for the name to become more intuitive. (Well, I reckon the general idea is ‘HOW was this kind of thing made’ or something? `o`)
gfldex WHAT is it and HOW was it constructed. 18:53
Tirifto_ The docs do say that ClassHOW is not a part of the language proper, which would make me hesitate to use it.
nemokosch There is a bit of schism when it comes to these things
Tirifto_ I should probably play around with meta-objects for a bit to make them feel more natural. 18:54
gfldex The MOP is considered stable. However, you should always `use v6.d`.
I "got" the whole Metamodel-stuff after reading the code: github.com/rakudo/rakudo/tree/main.../Metamodel
Tirifto_ gfldex, is it considered stable in Raku or Rakudo?
nemokosch Considered by whom?
gfldex In Raku.
nemokosch I doubt it's covered by tests to any serious extent 18:55
Tirifto_ gfldex, about the code you linked (for which I thank you!), how does ‘my role :: {}’ differ from ‘my role {}’? What is the purpose of the ‘::’ in this instance? `o` 18:57
gfldex see: github.com/Raku/roast/tree/master/S12-meta
It's a matter of taste. When I see `my role {}` I don't quite know if I forgot to name it or if the name was left out intentional. 18:58
nemokosch I doubt these tests have anything about stuff like compose 19:00
gfldex To answer your question properly. If you can get it down without the MOP, you should. And you can't assume that all objects adhere to the Metamodel. We got NativeCall and that can import very alien things into a Raku program.
Tirifto_ gfldex, is the ‘::’ the namespace (package?) separator, used to explicitly say that the name is empty/non-existent in this case? 19:01
MasterDuke fwiw, there are 8 instances of `.^compose` in roast 19:02
gfldex I think it's a hardcoded grammar thing to say "intentionally left blank".
nemokosch In the meta folder?
MasterDuke 1 in introspection, 7 in meta 19:03
nemokosch I'll have to check the synopses. Originally, the metamodel was deliberately vague and not speculative and it seemed like the minimal tests are written in that spirit 19:06
MasterDuke i didn't actually look at the tests, so very well could be 19:07
nemokosch classhow.t only consists of tests derived from Rakudo issues...
Tirifto_ On the metamethod call: Is ‘.^name(…)’ supposed to always be equivalent to ‘.HOW.name(…)’? 19:09
nemokosch iirc it also passes the metaobject as an argument 19:10
MasterDuke yeah. `.^foo` method calls are just syntax sugar for `.HOW.foo
gfldex $thing.^foo(…) is the same as $thing.how.foo($thing, …) 19:11
Tirifto_ @nemokosch Oh wait… the metaobject, or the original object? :o
nemokosch Well, I'm gonna trust gfldex with this one
Makes more sense
Tirifto_ Okay, yeah, that seems to be the case. 19:12
m: say 3.^name; say 3.HOW.name(3);
camelia Int
Int
Tirifto_ m: say 3.HOW.name;
camelia Too few positionals passed; expected 2 arguments but got 1
in block <unit> at <tmp> line 1
Tirifto_ Ahh, I understand now. So the metaobjects (which normally happen to be ClassHOW, right?) normally have methods which are meant to be called on ordinary objects to provide information about them (or perhaps rather about their clasess?)… is that right? 19:15
gfldex Yes, and then some.
nemokosch Usually about the class, or whatever it is 19:16
Like the attributes of it, methods of it, mro chain
I think can also exists on the metaobject 19:17
gfldex The cool thing about Metamode::* is that they behave like classes, so you can subclass. see: gfldex.wordpress.com/2021/08/17/most-fancy/
nemokosch $blah.^can('method-name') 19:18
Tbh the underscore method names are just enough proof that this wasn't meant to be public 😅 19:19
Tirifto_ gfldex, is ‘compose’ necessary to call after adding methods to the role, in order to make them available for use? 19:24
gfldex yes
compose wires up the method cache
Tirifto_ gfldex, thank you! Now I understand your code, and can say that it is beautiful. c: 19:29
I shall strive to make mine less so!
gfldex If you don't want to use the MOP to solve your problem, you could implement method FALLBACK. But that would be rather slow. 19:30
Tirifto_ I don’t really see a way to make use of FALLBACK that would be less complex than the other mentioned ideas. (But I might just be missing something.) `o` 19:33
20:16 deoac joined 20:20 teatwo left 20:21 teatwo joined 20:32 deoac left 23:47 Manifest0 left