> On 11 Apr 2016, at 15:19, Itsuki Toyota (via RT) 
> <perl6-bugs-follo...@perl.org> wrote:
> 
> # New Ticket Created by  Itsuki Toyota 
> # Please include the string:  [perl #127879]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=127879 >
> 
> 
> See the following results.
> 
> $ echo "h o g e" | perl6 -e 'for $*IN.lines -> $line { $line.split(" 
> ").map(-> $e { $e.perl.say; }) };' # map ignores the input
> $ echo "h o g e" | perl6 -e 'for $*IN.lines -> $line { $line.split(" 
> ").perl.say };' # ensure the input sequence
> ("h", "o", "g", "e")
> $ perl6 -e '("h", "o", "g", "e").map(->$e { $e.perl.say });' # ordinary case
> "h"
> "o"
> "g"
> "e"
> 
> 
> The 1st example seems that map subroutine ignores the input sequence. 
> I think that the 1st example should return the same result as the 3rd example.

I’m not sure.

$*IN.lines is lazy, the for is lazy, the split is lazy, the map is lazy, and 
apparently the sink is also lazy.  There’s nothing pulling values from the far 
end, so the whole chain is waiting for something to happen.

This should probably create a warning like “Useless use of split in sink 
context”.

If you make the split eager by storing its result, it works as you’d expect:

$ echo "h o g e" | perl6 -e 'for $*IN.lines -> $line { my @a = $line.split(" 
").map(-> $e { $e.perl.say; }) };'
"h"
"o"
"g"
“e"


So I would qualify this as *not a bug*, although one could argue that the lack 
of warning on the split in sink context *is* a bug.  And/or the lack of 
eagerness of the sink is a bug.



Liz

Reply via email to