🦋 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.
01:07 hulk joined 01:08 kylese left 01:30 guifa left 02:15 hulk left, kylese joined 02:30 kylese left 02:35 kylese joined 04:37 skyesoss joined 04:45 derpydoo joined 05:29 thaewrapt left 05:32 skyesoss left 05:40 thaewrapt joined 05:45 thaewrapt left 05:56 thaewrapt joined 05:57 skyesoss joined 06:01 thaewrapt left 06:12 thaewrapt joined 06:16 kst left 06:38 thaewrapt left 06:51 thaewrapt joined 06:57 thaewrapt left 07:07 thaewrapt joined 07:13 thaewrapt left 07:24 thaewrapt joined 07:31 thaewrapt left 07:41 skyesoss left, thaewrapt joined 07:48 thaewrapt left 07:49 Sgeo left 07:53 sena_kun joined 07:58 thaewrapt joined 08:03 thaewrapt left 08:08 kst joined 08:14 thaewrapt joined 08:20 thaewrapt left 08:31 thaewrapt joined 08:35 thaewrapt left 08:46 thaewrapt joined 08:47 derpydoo left 08:56 thaewrapt left 09:07 thaewrapt joined 09:14 thaewrapt left 09:21 tjr left 09:25 thaewrapt joined 09:30 thaewrapt left 09:41 thaewrapt joined 09:51 thaewrapt left 10:02 thaewrapt joined 10:09 thaewrapt left 10:20 thaewrapt joined 10:28 thaewrapt left 10:31 CIAvash joined 10:39 thaewrapt joined 10:51 thaewrapt left 10:56 tjr joined 11:03 thaewrapt joined 11:09 thaewrapt left
tbrowder howdy, question about a class object generated by a single factory class: can the new class have a reference to the factory class and call a method on it? i want to avoid duplicate instantiation of a shared object (a "heavy" font object). thanks 11:18
tellable6 2024-07-20T00:37:26Z #raku <wayland76> tbrowder Oh! That makes sense. Thanks :)
11:20 thaewrapt joined 11:27 thaewrapt left 11:38 thaewrapt joined 11:44 thaewrapt left 11:46 thaewrapt joined 11:50 CIAvash left 11:53 thaewrapt left 12:04 thaewrapt joined
librasteve tbrowder: I guess your "single factory class" implemented as a singleton (ie instead of just class methods, there is a [single] instance that can run the method gimme-new-thing - in which case then you can have class new-thing {has $.factory; ...} and set the $factory attr to the self of the factory instance. If new-think is a class object, then maybe it needs to have a my $factory and you have to set that via a 12:15
class method on new-thing...
12:16 thaewrapt left 12:27 thaewrapt joined 12:34 thaewrapt left 12:44 thaewrapt joined 12:51 thaewrapt left 12:57 thaewrapt joined 13:04 wayland left, wayland joined 13:15 MasterDuke joined
vendethiel m: sub f($x) { return my class :: { method f { $x } } }; my $a = f(1).new; my $b = f(2).new; say $a.f; say $b.f 14:03
evalable6 2
2
Raku eval 2 2
14:04 mrnoia joined 14:05 mrnoia left 14:31 CIAvash joined
tbrowder librasteve: thanks for the info. i looked at the singleton thing for the factory but i don't think i need it because my scripts using it only use one instance. the hatched objects are all effectively siblings and don't commmunicate with each other. 14:39
ugexe have the factory add a runtime role that adds the method from the factory class 14:43
tbrowder given that do you see any problems with yr suggestion? it sounds like it should work fine. (i have to go soon but will try it later today.) 14:44
ugexe class MyFactory { my role DoFactoryMethod { method do-it { $.factory-method } }; method factory-method { 42 }; method new { my $factory-created = MyOtherClass.new but DoFactoryMethod } } 14:45
something like that
tbrowder ugexe: i didn't see yr reply before i answered librasteve
ugexe er the code i posted isn't correct so ignore that part of my response 14:46
antononcube @tbrowder class FontFactory { has $.font; method get-font { return $!font //= self.create-font; } method create-font { # Simulate heavy font creation note '⎡DOING .create-font.⎦'; return "Heavy Font Object"; } } class TextObject { has FontFactory $.factory; method new-text { my $font = $!factory.get-font; say "Using font: $font"; 14:48
} } my $factory = FontFactory.new; my $text1 = TextObject.new(factory => $factory); my $text2 = TextObject.new(factory => $factory); $text1.new-text; # Using font: Heavy Font Object $text2.new-text; # Using font: Heavy Font Object
tbrowder i need to show a gist of how i want it to act. basically the factory has as an attribute a list of distinct font objects that its offspring should use as is--just interrogating the list. 14:49
antononcube When run the code above should give: ⎡DOING .create-font.⎦ Using font: Heavy Font Object Using font: Heavy Font Object
@tbrowder Hmm... I made/posted my code befor seeing your last clarification... 14:50
ugexe why not pass the list into the child objects 14:51
that would make testing the child objects easier as well
tbrowder hm, i forgot one important thing: the chidren may need a new font object that factory hasn't creeated. maybe use a global hash 14:53
ugexe the factory should really just be creating the children 14:55
tbrowder or a separate global singleton that just produces and holds requested font objects
and as you said factory just creates children 14:57
hm, thoughts to ponder on my road trip (when i'm not driving ;-D) 14:59
aha! i lied, each child only gets one font object, so the factory ensures they get a copy of an existing one (slapping forehead) 15:02
17:32 CIAvash left
antononcube weekly: youtu.be/LmLk9UB4_Ak 18:23
notable6 antononcube, Noted! (weekly)
20:17 thaewrapt left 20:19 skyesoss joined 20:21 thaewrapt joined 20:25 thaewrapt left 20:29 thaewrapt joined 21:43 sena_kun left 22:02 jrjsmrtn_ joined, jrjsmrtn left 22:13 cm_ joined 22:15 cm left, cm_ is now known as cm