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.
00:42 jaguart left 00:57 jaguart joined 01:09 habere-et-disper left
falsifian 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:20
01:23 deoac joined
deoac I would like to match any of the keys of a hash 01:24
my %foo = ( a => 1, b => 2 );
my regex bar { "{ %foo.keys>>.lc.any }" }
`'a' ~~ / <bar> /` 01:25
This type cannot unbox to a native string: P6opaque, Junction
  in block <unit> at <unknown file> line 1
Is there any way to do this?
falsifian deoac: Does it need to be in a regex? If not, there's just 'a' eq %foo.keys.any. 01:26
m: my %foo = ( a => 1, b => 2 ); say 'found it' if 'a' eq %foo.keys.any; 01:27
camelia found it
01:29 MasterDuke joined
deoac Yes, it needs to be able to find the `a` in `123a456` 01:31
Nemokosch 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
falsifian 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:38
I want to change the line a bunch of times, then print the result of all those changes. 01:39
Nemokosch not on something that comes from the input of the program. You would need to copy it at least 01:40
I wonder if there is something like 01:41
for lines -> $_ is copy {}
MasterDuke `for lines() -> $_ is copy { s:g/a/b/; .say };`  # you need the '()' 01:42
Nemokosch oh right, the "needs parens to avoid gobbling block" message 01:43
MasterDuke yep
Nemokosch has anyone ever figured out what a "gobbling block" is?
falsifian To stop lines from gobbling the block 01:44
It's not a "gobbling block"
MasterDuke gobbling is a verb in that message
Nemokosch 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:46
an article would help with the syntax but not with the word overall 01:47
falsifian 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
MasterDuke 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
Nemokosch [lazy lines]? xD worth a try... 01:50
falsifian omg it worked
Nemokosch there are two levels of laziness, if that makes sense 01:51
lines() is lazy but not lazy enough to know this about itself
however, if you construct anything with the lazy keyword, that's gonna be so lazy that it knows about itself 01:52
falsifian 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?
Nemokosch I think [] coerces into an Array under the hood but that's pretty easy to check 01:53
it's the circumfix [] operator
falsifian 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.
Nemokosch github.com/rakudo/rakudo/blob/2022...ors.pm6#L7 this is where it appears in the sources (2022.12 because that's what I have) 01:55
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:58
and this happens with the iterator backing up an expression like lazy lines 01:59
02:14 jaguart left 02:16 tea3po left, tea3po joined 02:37 deoac left 05:58 Heptite left 11:12 jaguart joined 11:21 jaguart left 11:52 habere-et-disper joined
lizmat And yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2023/05/01/2023-...ou-moritz/ 12:02
habere-et-disper Thank you lizmat ! Always lovely to read. 12:22
:-)
14:15 teatwo joined 14:19 tea3po left 14:55 human_blip left, 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