| 1 Mar 2026 | |||
| ab5tract | anyway, we've already got a few ways to do it :) | 11:16 | |
| lizmat | yeah, but I also do find $a = $_ with $b a bit cumbersome :-) | 11:17 | |
| wouldn't mind some syntactic sugar for that | |||
| ab5tract | yeah fair | 11:40 | |
| arkiuat | huh, I thought it was the same | 13:44 | |
| m: my ($F,$f); $F //= $f; dd :$F; $f = 1; $F //= $f; dd :$F | |||
| camelia | :F(Any) :F(1) |
||
| arkiuat | m: my ($F,$f); $F = $_ with $f; dd :$F; $f = 1; $F = $_ with $f; dd :$F | 13:45 | |
| camelia | :F(Any) :F(1) |
||
| arkiuat | so what's the difference exactly? | ||
| lizmat | /= means: assign if the LHS is undefined | 13:46 | |
| //= means: assign if the LHS is undefined | |||
| (one / eaten :-) | |||
| $a = $_ with $b means: assign RHS if RHS is defined | 13:47 | ||
| arkiuat | oh right! OP was asking about assigning if RHS is defined | 13:48 | |
| lizmat | yup | ||
| arkiuat | I misread the original question | ||
| sorry deoac | |||
| I don't run into that situation nearly as often as I want to assign to LHS but only if it's not already defined | 13:50 | ||
| thanks for explaining | 13:52 | ||
| lizmat | yw :-) | 13:53 | |
| librasteve | think I’ll go and crawl into a hole (thanks for correcting me) | 13:57 | |
| arkiuat | eh, you're fine. I made a worse mistake | 14:12 | |
| you just made a typo in a question. I went blathering on answering a question that hadn't been asked | 14:13 | ||
| 2 Mar 2026 | |||
| librasteve_ | rakudoweekly.blog/2026/03/02/2026-...0-2026-02/ | 19:03 | |
| 4 Mar 2026 | |||
| modula | Hi. I'm trying to do this: gather { for (^100) { my $c = (0x20..0xFFFF).pick; try { $c = $c.chr; CATCH { next } }; take $c; } } but even though I have this wrapped in a `try` and `CATCH`, I still get errors like "Error encoding UTF-8 string: Could not encode Surrogate codepoint 55551". All I want is to run `next` to skip the current iteration if `$c.chr` throws any error. Why does this not | 08:00 | |
| work, and how can I make it work? | |||
| librasteve | hi modula | 11:02 | |
| let me see what I can make of that | |||
| hmmm - the error seems to be happening at the output stage (I prepended say to your code) | 11:18 | ||
| - I tried forcing the stringification inside the try block with $c = $i.chr.Str | 11:19 | ||
| but that did not improve matters - maybe someone more expect than I can help? | |||
| sorry | 11:20 | ||
| lizmat | modula: that's very perl like code :-) | 11:34 | |
| fwiw, that code doesn't fail for me | |||
| which version of rakudo are you using ? | |||
| ah... need a "dd" in front to make it fail | 11:35 | ||
| could it be that it is just an invalid code point that was picked ? | 11:38 | ||
| hmm.. looks like the .chr error is not trappable | 11:40 | ||
| m: .say with try 56792.chr | |||
| camelia | Error encoding UTF-8 string: could not encode Unicode Surrogate codepoint 56792 (0xDDD8) in block <unit> at <tmp> line 1 |
||
| lizmat | modula: golfed your code to: | 11:43 | |
| m: gather { for (0x20..0xFFF).pick(100) { .take with try .chr } } | |||
| camelia | ( no output ) | ||
| lizmat | m: dd gather { for (0x20..0xFFF).pick(100) { .take with try .chr } } | ||
| camelia | ("", "ݰ", "", "ଲ", "ԁ", "Æ", "Ƃ", "Ν", "", "\x[81D]", "", "", "ɕ", "ੋ", "ؤ", "Ӓ", "\x[59B]", "ˈ", "", "\x[749]", "Ǯ", "ໜ", "ۏ", "మ", "܉", "प", "", "", "ࡢ", "ಽ", "ৣ", "ໍ", "", "۾", "\x[ECB]", "… | ||
| lizmat | will make an issue for 56792.chr not being trappable | ||
| hmmm.. as librasteve noted, it's really in the stringification | 11:53 | ||
| m: say 56792.chr.ord | |||
| camelia | 56792 | ||
| lizmat | m: try say 56792.chr # trappable indeed | 11:56 | |
| camelia | ( no output ) | ||
| modula | lizmat: thanks, your golfed version works :) and yes, i'm definitely much more familiar with perl, it was my first language years ago, but i've been trying to gradually learn raku more, it seems like a very cool language. thanks again for your help! | 19:56 | |