8

I really can't find another explanation for this:

for <a b> -> $foo {
    spurt "a/b", "bar";
}
say "Gotcha";
for <a b>  {
    spurt "a/b", "bar";
}

This prints "Gotcha" and then fails. I get that the last value in a loop is returned, and that if nothing is done with it it's in sink context, but what kind of change brings declaring a variable to it? It's still a Block, far as I can tell.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 1
    Didn't you revert the order of the parameters of `spurt`? Assuming you want to write to a file called "bar" – Elizabeth Mattijsen Apr 29 '20 at 17:34
  • 1
    @ElizabethMattijsen But then it works. I presume JJ's point is that writing to "a/b" fails because there's no "a" directory. But the failure passes unreported. Yet in the second block the failure crashes the program. Why the difference? – raiph Apr 29 '20 at 20:14
  • 2
    The second block signature `(;; $_? is raw = OUTER::<$_?>)`, the first `($foo)`. That doesn't explain it at all but I wanted to note it. – raiph Apr 29 '20 at 20:19
  • If I replace the `spurt`s by `Failure.new` (which is the equivalent I would say in this situation), then both loops throw with the line number of the `for`, and a postscript "Actually thrown at" with the line number of the `Failure.new`. Is this also what you see? Or do you see something different? – Elizabeth Mattijsen Apr 30 '20 at 08:51
  • @ElizabethMattijsen I don't think I did... https://docs.perl6.org/language/independent-routines#sub_spurt; I want to write to "a/b" which is why it fails, `a` does not exist. @raiph is right. Anyway, I was curious why it failed in this situation... Maybe it's not the same as directly creating a failure. – jjmerelo Apr 30 '20 at 10:45
  • 2
    @ElizabethMattijsen That was about the first thing I tried. On repl.it (`say $*RAKU.compiler.version; # v2020.02.1`), tio.run (`say $*PERL.compiler.version; # v2018.12`), and glot.io (`v2018.04.1`), I saw the same as what JJ reported in his question body, and the same as what you report when replacing the `spurt`s with `Failure.new`s. So while they might (seem to) be *logically* equivalent, they're not *actually* equivalent in those three Rakudo installations covering mid 2018 thru to today. – raiph Apr 30 '20 at 12:56
  • Did you get to the bottom of this? It smells to me like [another bug in the kitchen](https://stackoverflow.com/a/54469963/1077672). – raiph May 09 '20 at 21:29
  • @raiph I didn't. Maybe I'll post an issue in rakudo. – jjmerelo May 10 '20 at 07:06
  • 1
    @jjmerelo Hopefully you saw that for the bug I linked "`->` syntax [was] part of the regression or new bug" which suggests it's related to this one and suggests that "`->` and sinking" or somesuch is the appropriate topic for a bug report that could then cite both this SO and the earlier one by you that I linked as examples. I'll post an issue of that form later today if I don't see one already there. – raiph May 10 '20 at 08:56

1 Answers1

1

Using Rakudo 2022.07

returns:

Gotcha
Failed to open file /Users/admin/a/b: No such file or directory
  in block <unit> at - line 6
jubilatious1
  • 1,999
  • 10
  • 18