🦋 Welcome to Raku! raku.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: colabti.org/irclogger/irclogger_log/raku
Set by ChanServ on 14 October 2019.
gfldex lolibloggedalittle: gfldex.wordpress.com/2021/02/28/un...ape-hatch/ 13:30
codesections gfldex: I don't think that's really _undocumented_ (though I'm sure it could be clearer). But the docs say that `given` is a statement and, in general, statements don't return a value -- but they *do* return a value when preceded by `do`, when wrapped in parentheses, or when they are the final element in a block. 14:46
m: sub f() { my $a = 42 }; say f 14:47
camelia 42
gfldex codesections: that succeed can return a value is undocumented. 17:33
guifa vrurg: it’s really nice though 20:05
vrurg: what do you think should be the best approach, though, for role coercion where the role is fully stubbed? 20:06
For my rewrite of LanguageTag, I was wanting to heed someone’s request for a light version 20:08
so I was thinking doing a role LanguageTaggish with stubbed methods. Then I’d have my complete concrete implementation as class LanguageTag does LanguageTaggish. But there’d be a lightway role, role LanguageTag::Light does LanguageTaggish that could be applied to strings that would calculate the methods on the fly (trading creation speed/memory footprint for slower method calls). 20:11
given a signature \(LanguageTaggish() $tag), how do you think I should best handle that circular dependency? I could probably do the LanguageTaggish and the ::Light in one file, but the purist in me wants them in separate files ha 20:12
guifa codesections: oooh, I just found something potentially dangerous with does vs but 20:30
well, s/dangerous/performance killing
Role A { method a { ‘a’ } }; my @a; @a.push: ‘foo’ but A for ^100; say @a.tail.WHAT 20:31
m: Role A { method a { ‘a’ } }; my @a; @a.push: ‘foo’ but A for ^100; say @a.tail.WHAT 20:32
camelia 5===SORRY!5===
Undeclared names:
A used at line 1
Role used at line 1

Other potential difficulties:
Useless declaration of a has-scoped method in mainline (did you mean 'my method a'?)
at <tmp>:1
------> 3Role…
guifa m: role A { method a { ‘a’ } }; my @a; @a.push: ‘foo’ but A for ^100; say @a.tail.WHAT
camelia (Str+{A})
guifa m: role A { method a { ‘a’ } }; my @a; @a.push: ‘foo’ does A for ^100; say @a.tail.WHAT 20:33
camelia (Str+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A…
guifa even WORSE
(I’m guessing because strings are valuetypes and roles don’t affect that) 20:34
m: role A { method a { ‘a’ } }; my @a; @a.push: ‘foo’ does A for ^100; say ‘foo’.WHAT
camelia (Str+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A}+{A…
perry AAAAA 20:37
vrurg guifa: you're trying to fit too much into too short sentence, perhaps. :) I don't see a circular dependency in your case but rather a clear tree with LanguageTaggish been the root and two branches. 20:53
guifa vrurg: sorry! I’m know for being long-winded 20:54
vrurg so am I, no worries. But this is certainly the opposite case. I either overlooking an important details, or you didn't mention it. 20:55
guifa vrurg: I guess I’m concerned about LanguageTaggish.COERCE. Since the Taggish role is abstract, it’ll need to apply the Tag::Light role or create a Tag class object 20:56
vrurg guifa: why `self.new` in `CORECT` won't work for you? 20:59
guifa because all of the relevant methods are stubbed, so it wouldn’t be a meaningful coercion 20:59
basically, this is what I have (simplified for only the language part) 21:00
role Taggish { method language { … } }; role Taggish::Light does Taggish { method language { self.Str.split(‘-‘)[0] }; class Tag does Taggish { has $.language }  21:01
vrurg Aha, this is what I miss...
Then there is no really good solution. There is no way for COERCE to know what to convert into. I'd stub it too and provide implementations by the consuming classes/roles. 21:03
But if you imply that by default LanguageTaggish coerces into ::Light then just import it run-time and use as ::('LanguageTaggish::Light').new 21:05
guifa That’s true. I’m just debating which one I prefer to be the default haha.
the “Light” is only light by memory footprint so far. `but` isn’t exactly super fast compared to creating even moderately objects 21:06
moderately complex objects
vrurg guifa: Actually, stubbing COERCE will not work as LanguageTaggish() would remain non-functional. So, only run-time import remains. 21:07
I would probably re-consider the model in a way to avoid LanguageTaggish() altogether. 21:08
guifa That’s also very fair. There are a few other language tag models other than BCP47, so I was trying to come up with a way that would conceptually play well with them 21:09
Maybe I could just make the TagLight a class that has a single string attribute (extremely fast to make and coerce back into a Str) instead of a role to apply to a Str 21:10