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.
jgaz Apparently the precedence of = is too loose for the ?? ternary operator? Why is that? I was able to "fix" it with `<test> ?? ($foo = val) !! ($bar = val)`, but I'm not sure that's optimal either. 18:42
nemokosch isn't that the normal way? I can't think of a language where you'd need to write variable = (condition ? aValue : bValue), with the parens 18:44
jgaz I don't think I have to do that in Perl, I can check...
nemokosch the ternary operator is not for side effects, after all 18:46
the true irony is, though, that your example can be rewritten without parens, if you want to golf it so badly: 18:48
jgaz Okay, so I can make it work, but the precidence is wrong if I have an equals. It silently fails to do the right thing.
nemokosch <test> ?? $foo !! $bar = val
jgaz Silent failure is Perl 5. 18:49
hmm... okay.
nemokosch I would say it looks weird but it seems to do the "set one of the variables to val, depending on the test" thing
jgaz I will say, at least Raku gives me a warning that there is a precidence issue. 18:52
IDK if it's code golf exactly, but yeah, I like to do as much as I can on one line as reasonably possible. 18:53
This is especially true on a return line.
nemokosch If you are okay with repeating val, I'd definitely prefer an if-else 18:55
if not, then maybe (<test> ?? $foo !! $bar) = val, with the parens for readability
jgaz Hmm... I'll play with that. 18:57