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.
falsifian ("{$_}" for ^1).join eq "0" --> True (as I expect) 15:04
die unless ("{$_}" for ^1).join eq "0"
Use of uninitialized value $_ of type Any in string context.
Doesn't happen if I use "$_" instead of "{$_}".
What's going on?
Nemokosch falsifian: {} creates a block with its own $_ 15:22
falsifian Nemokosch: Even {} in string interpolation? Then why did the first one (without die) work?
Nemokosch I also wonder about the first one 15:23
falsifian Nemokosch: Also, even outside string interpolation, I don't see {...} always getting rid of $_ 15:25
e.g. for (^3) { say $_; { say $_; } }
Prints each number twice. The inner {} didn't get rid of $_.
Nemokosch fair point, although I think that's because the inner $_ gets bound to the outer one. Wouldn't know from the top of my head, to be honest 15:26
lizmat m: say { say "foo" }.signature 15:27
camelia (;; $_? is raw = OUTER::<$_>)
lizmat note how the default value for the argument $_ is the outer $_
Nemokosch phew, seems like I did manage to understand something, after all 15:28
but then we might as well ask the difference, still 15:29
the prefix if/unless works, the postfix one does not 15:30
I think we've had code generation problems regarding for 15:32
github.com/rakudo/rakudo/issues/5049 this is what I remembered 15:34
really hard to imagine that this isn't a bug 15:37
m: say 'TRU' if { .say } ; 15:46
interesting the least to say 15:47
m: say 'TRU' if { .say } ;
lizmat m: say 'TRU' if { .say } 15:49
camelia TRU
Nemokosch are blocks evaluated to true without being called?
lizmat that'd be a considered a postfix if with a block as a parameter, and the block is *not* being run
Nemokosch seems like that 15:50
lizmat like any instantiated object by default
m: class A { }; say "class" if A; say "instance" if A.new
camelia instance
Nemokosch that's the strange part of strangely consistent 😛
(still better than strangely inconsistent though) 15:51
lizmat m: class A { method defined(--> False) { } }; say "class" if A; say "instance" if A.new
camelia instance
lizmat m: class A { method Bool(--> False) { } }; say "class" if A; say "instance" if A.new
camelia ( no output )
lizmat it's just that the Any:D Bool defaults to True
Nemokosch this makes sense but it's a dead end for what I wanted to see about that weird {$_} 15:53
but now it works... 15:55
maybe it was some REPL weirdness all along?
m: die unless ("{$_}" for ^1).join eq "0" 15:56
no, the REPL weirdness was that it worked for a while xd 15:57
lizmat the REPL is not a good place to test complicated behaviours 16:02
Nemokosch to be fair though, this shouldn't be complicated at all
sadly, this seems to be deep in the "strangely inconsistent" territory 16:03
falsifian m: die unless ("{$_}" for ^1).join eq "0" 16:29
camelia Use of uninitialized value $_ of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
in block at <tmp> line 1
Died
in block <unit> at <tmp> line 1
falsifian m: say ("{$_}" for ^1).join eq "0"
camelia True
falsifian I first observed this outside the REPL. 16:30
lizmat and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2022/12/05/2022-...mas-again/ 17:02
Nemokosch somehow the $_ doesn't propagate in that block but I really can't say much more than it's probably a bug. Feel free to open an issue for it at github.com/rakudo/rakudo/issues so that it doesn't get lost 17:05
falsifian Will do after work if someone else doesn't get to it first. Thanks for the answers! 17:21
baughb I want to read (and process) a file line-by-line, until I find an empty line, and then continue reading (and processing in a different way) line-by-line until the end. My idea was to bind `.IO.lines` with something like `my \lines = 'file'.IO.lines` and then run two for loops over it, but then I get the "The iterator of this Seq is already in 17:29
use/consumed" error. Is there some other way to do this lazily, without caching the file?
lizmat my $after; for $io.lines { if $after { say "after" } elsif !$_ { $after = True } else { say "before" } } 19:47
Nemokosch something with ff could also work - not sure if it's genuinely worth it 19:55
lakmatiol yeah, this seems ideal for ff 20:14
```perl 20:24
for lines() {
if "" ff * {
say "after";
} else {
say "before";
}
}
```