7

In this program:

use v6;
my $j = +any "33", "42", "2.1";
gather for $j -> $e {
    say $e;
} # prints 33␤42␤2.1␤

for $j -> $e {
    say $e; # prints any(33, 42, 2.1)
}

How does gather in front of forchange the behavior of the Junction, allowing to create a loop over it? The documentation does not seem to reflect that behavior. Is that spec?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 2
    I believe this is a bug in rakudo, and I guess it's related to some builtin not having a parameter typed `Mu` that should be, but I can't form a clear mental model of what's happening. – moritz Sep 26 '19 at 18:48

1 Answers1

4

Fixed by jnthn in code and test commits.


Issue filed.

Golfed:

    do put .^name for any 1 ; # Int
       put .^name for any 1 ; # Mu

Any of ten of the thirteen statement prefixes listed in the doc can be used instead of do or gather with the same result. (supply unsurprisingly produces no output and hyper and race are red herrings because they try and fail to apply methods to the junction values.)

Any type of junction produces the same results.

Any number of elements of the junction produces the same result for the for loop without a statement prefix, namely a single Mu. With a statement prefix the for loop repeats the primary statement (the put ...) the appropriate number of times.

I've searched both rt and gh issues and failed to find a related bug report.

raiph
  • 31,607
  • 3
  • 62
  • 111
  • 3
    Just call it a feature. – Holli Sep 26 '19 at 22:30
  • Without the statement prefix, shouldn't `for any 1` be a Junction, not a Mu? – jjmerelo Sep 27 '19 at 05:08
  • 2
    @jjmerelo That's what I would expect. (I mostly avoid using [the word "should"](https://www.google.com/search?q=the+word+%22should%22). But pedanticism aside, a roast test that specifies that `for any 1` and `quietly for any 1` and `for (any 1,)` all deliver an `any 1` makes sense to me.) I thought last night that delivering the `Mu` type object is spectacularly useless and a bug. Having slept on it I still do. (I upvoted Holli's sarcastic comment but that was just for the grim humor of it.) – raiph Sep 27 '19 at 10:33
  • Hi @jjmerelo. I noticed you haven't accepted my answer, which suggests there might be something you're looking for beyond "it's a bug" and a filed bug report. If you elaborate I might be able to address what you're missing. TIA for any advice. – raiph Sep 30 '19 at 14:20
  • @raiph it's because I was looking for an explanation, actually. No problem accepting it, though. As if there were other options – jjmerelo Oct 01 '19 at 08:05
  • @jjmerelo I think of TIMTOWTDI and TAAOO (there are always other options) as siblings. :) Are you saying you'd like an explanation ***of*** the bug (as against [an explanation that something ***is*** a bug](https://meta.stackoverflow.com/a/303976/1077672))? (I suspect an explanation *of* the bug is far beyond my paygrade, and also beyond what SO is supposed to be about, which is why I have stopped where I have. But it can't hurt to know for sure what you seek.) – raiph Oct 01 '19 at 12:06