[00:42] *** jaguart left [00:57] *** jaguart joined [01:09] *** habere-et-disper left [01:20] for (lines) { .say if s/a/b/ } fails with "Cannot modify an immutable Str". I can write something like for (lines) { my $a = $_; $a.say if $a ~~ s/a/b/ } instead. Is there a less awkward way around the error? [01:23] *** deoac joined [01:24] I would like to match any of the keys of a hash [01:24] my %foo = ( a => 1, b => 2 ); [01:24] my regex bar { "{ %foo.keys>>.lc.any }" } [01:25] `'a' ~~ / /` [01:25] This type cannot unbox to a native string: P6opaque, Junction [01:25]   in block at line 1 [01:25] Is there any way to do this? [01:26] deoac: Does it need to be in a regex? If not, there's just 'a' eq %foo.keys.any. [01:27] m: my %foo = ( a => 1, b => 2 ); say 'found it' if 'a' eq %foo.keys.any; [01:27] rakudo-moar 80c35e427: OUTPUT: «found it␤» [01:29] *** MasterDuke joined [01:31] Yes, it needs to be able to find the `a` in `123a456` [01:37] for matching, you can have m// that always matches on the topic (including smartmatching), or just a plain regex (e.g //) with smartmatching [01:37] s/// is mutating substitution [01:38] Nemokosch: Where this actually came up was more like for (lines) { s:g/a/b/; s:g/c/d/; ...more... .say }. I do indeed want to be mutating a string, and was hoping I could be lazy like that. [01:39] I want to change the line a bunch of times, then print the result of all those changes. [01:40] not on something that comes from the input of the program. You would need to copy it at least [01:41] I wonder if there is something like [01:41] for lines -> $_ is copy {} [01:42] `for lines() -> $_ is copy { s:g/a/b/; .say };`  # you need the '()' [01:43] oh right, the "needs parens to avoid gobbling block" message [01:43] yep [01:43] has anyone ever figured out what a "gobbling block" is? [01:44] To stop lines from gobbling the block [01:44] It's not a "gobbling block" [01:44] gobbling is a verb in that message [01:46] to be honest, if I can't even tell if it's a verb or not, that's even further from awesome to me xD [01:47] an article would help with the syntax but not with the word overall [01:48] I can also write for [lines] { s/a/b/; .say; } but it consumes the whole input first. Is there a slick way to wrap a lazy sequence in scalar containers, like a lazy version of [...]? [01:48] i'll admit i frequently write like that, even though i don't think it's 100% correct english. but yes, 'gobbling *the* block' would probably be an improvement [01:50] [lazy lines]? xD worth a try... [01:50] omg it worked [01:51] there are two levels of laziness, if that makes sense [01:51] lines() is lazy but not lazy enough to know this about itself [01:52] however, if you construct anything with the lazy keyword, that's gonna be so lazy that it knows about itself [01:52] That's really interesting. Can you be more specific? Is the [...] constructor querying some attribute of (lines) or (lazy lines) to decide whether to consume it all? [01:53] I think [] coerces into an Array under the hood but that's pretty easy to check [01:53] it's the circumfix [] operator [01:54] g2g; will read more about it later. I wonder if lines should be changed to behave more like lazy lines. Thanks Nemokosch. [01:54] This comes up sort-of frequently for me so nice to have [lazy lines] as an easy trick. [01:55] https://github.com/rakudo/rakudo/blob/2022.12/src/core.c/array_operators.pm6#L7 this is where it appears in the sources (2022.12 because that's what I have) [01:58] generally, the inspectable laziness is defined on iterators - which is quite strange, I would say, as iterators are conceptually lazy. For an iterator to be "lazy" means that it signals you that it doesn't want to give you a value [01:59] and this happens with the iterator backing up an expression like lazy lines [02:14] *** jaguart left [02:16] *** tea3po left [02:16] *** tea3po joined [02:37] *** deoac left [05:58] *** Heptite left [11:12] *** jaguart joined [11:21] *** jaguart left [11:52] *** habere-et-disper joined [12:02] And yet another Rakudo Weekly News hits the Net: https://rakudoweekly.blog/2023/05/01/2023-18-thank-you-moritz/ [12:22] Thank you lizmat ! Always lovely to read. [12:22] :-) [14:15] *** teatwo joined [14:19] *** tea3po left [14:55] *** human_blip left [14:55] *** human_blip joined [15:10] *** habere-et-disper left [15:59] *** Heptite joined [17:45] *** explorer joined [21:19] *** guifa joined [23:01] *** MasterDuke left [23:55] *** guifa left [23:56] *** guifa joined