🦋 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.
Tirifto Is the usual syntax for default attribute values not supposed to work in declarations of custom subclasses of List? 00:26
m: class Gold is Array { has Int $.carats = 0 }; say Gold.new.carats; 00:27
camelia (Int)
Tirifto class Gold is List { has Int $.carats = 0 }; say Gold.new.carats;
evalable6 (Int)
Tirifto Oh wow, I had no idea camelia had competition. :o But anyway, is that intentional? Should that have been obvious from reading some part of the docs? 00:28
guifa_ Tirifto: it should probably be mentioned. I believe the issue is that List and Array have special .new() 01:13
rather than default to Any/Mu's .new 01:14
Tirifto Ah, so attribute defaults are dependent on .new. That makes sense, thank you, guifa_. 01:16
guifa_ either on .new or on one of the methods that get called by default by it (e.g. BUILD TWEAK etc)
for instance, if you call
Gold.new( carats => 1 ), how does it distinguish you wanting that from being the first item, or an attribute? 01:17
(technically, Pair.new('carats', 1) makes it a positional, and :1carats, carats => 1, :carats(1) make it named argument, but YMMV if relying on that is desirable) 01:18
Tirifto Yeah, it’s fairly apparent when passing values to »new«. Less so with the defaults we put in class definitions, though, since however Raku makes those happen is not that obvious to the naked eye, or at least not to that of mine. 01:20
Tirifto One could suppose it’s just a way of setting default values for the .new method (or some such), but my first assumption was that it was more direct than that. 01:23
Though I haven’t attentively read through classtut recently. x)
guifa_ could probably do this a bit more elegantly with a trait but 01:27
m: class Gold is Array { has Int $.carot; method new(|c) { callsame!defaults(|c) }; method !defaults(|c) { $!carot = c<carot> // 1; self } }; Gold.new(1,2,3).carot.say; Gold.new(1,2,3).say; Gold.new(1,2,3,:4carot).carot.say
camelia 1
[1 2 3]
4
guifa_ so first one you can see the default value of one is set, the next one shows an actual array is produced, and the last one shows the :4carot being interpreted as a default value 01:28
err as an attribuet value
okay 01:42
so I can't find a way to get the default value of an attribute
but this will probably be much cleaner for you
m: role Subarray[*%defaults] is Array { method new(|c) { callsame!defaults: |c }; submethod !defaults(|c) { .set_value(self, c.hash{.name.substr(2)} // %defaults{.name.substr(2)}) for (self.^attributes (-) Array.^attributes).keys; self } }; class Gold does Subarray[:0carot] { has Int $.carot }; Gold.new(1,2,3, :4carot).carot.say; Gold.new(1,2,3).carot.say, Gold.new(1,2,3).say 01:44
camelia 4
0
[1 2 3]
guifa_ now all you have to do is include that role, and you can just say `does Subarray[ attribute => default-value, attribute => default ]`. You have to repeat the attribute name in the Subarray parameterization and in the attributes, but otherwise fairly clean 01:46
hope that helps a bit :-) 02:05
[Coke] lizmat: did you happen to ever get raku-land running locally on your mac? 13:42
lizmat must admit I never tried
[Coke] ok. I hope to be able to spend some cycles later today trying to sort out my remaining issues.
If I get it working, will make sure we have a paragraph in the README 13:43
lizmat ++[Coke]
tonyo what are you doing in RL ? 13:55
[Coke] what is gmark? 17:55
gitlab.com/raku-land/raku-land/-/b.../bin/gmark 17:56
ah, github.com/gbagan/gmark maybe 17:57
[Coke] gitlab.com/jjatria/lorea/-/issues/4 - anyone else able to dupe this issue? 19:06
this seems to be the blocker for me. 19:10
(getting raku-land working locally)
[Coke] ok, have a broken version of raku-land in the firefox browser locally, that's progress. 19:53
[Coke] the css isn't being included for some reason. 20:24
missing the <link> to include it entirely.
can someone point me at what this is doing? gitlab.com/raku-land/raku-land/-/b...crotmp#L33 20:30
aha! 20:41
now have a nice looking local raku.land (with almost no dists because i only did one of each)
[Coke] is there a version of $*ARGS that doesn't include the options? 21:10
I mean @*ARGS
is there a whateverable that would let me test a distro with various versions? 21:13
gitlab.com/jjatria/lorea/-/issues/4 might fix it 21:23
[Coke] (gmark is github.com/yuin/goldmark btw) 21:42
[Coke] \o/ 22:27
Tirifto guifa_, thank you for those examples! For my current use case, a class with an array as an attribute will probably work fine, but your last example shows magic I wouldn’t have though of, and it’s very interesting to read. :-) 22:30
[Coke] raku.land/build has a few errors that could maybe be tickets on distros. 22:31
e.g. github: Could not resolve to a Repository with the name 'tony-o/p6-db-xoos-mysql'. 22:32
(wonder if that's from an old published version since latest m6 seems fine) 22:33
tonyo [Coke]: what're you hooking up in raku land? 23:55