I've determined that the issue is the +@partials. Sometimes that is returning 1 as the length of the list instead of the full list. It looks to be whenever the first index set returns the empty set, the size calculation fails.
________________________________ From: perl6 via RT <perl6-bugs-follo...@perl.org> Sent: Wednesday, November 23, 2016 5:15 PM To: tim.boll...@live.com Subject: [perl #130160] AutoReply: [BUG] Flattened list iteration Greetings, This message has been automatically generated in response to the creation of a trouble ticket regarding: "[BUG] Flattened list iteration", a summary of which appears below. There is no need to reply to this message right now. Your ticket has been assigned an ID of [perl #130160]. Please include the string: [perl #130160] in the subject line of all future correspondence about this issue. To do so, you may reply to this message. Thank you, perl6-bugs-follo...@perl.org ------------------------------------------------------------------------- It appears that when iterating lazily through a list that's been flattened (the first time), sometimes certain elements are not reached. For background I was writing some code that used a trie, and was attempting to find the word "inclusive" out of input trigrams. I have cleared away as much of the surrounding code as I could to provide a minimal test case. If you enable the commented line (or otherwise iterate through the @partials list at least once first), the output will be correct. Thanks, Tim Bollman use v6; sub find-words(@partials) { state $output = ''; # my @a = @partials.kv; for @partials.kv -> $i, $word { my $backup = $output; $output ~= $word; take $output; find-words(@partials[0 ..^ $i, $i ^..^ +@partials].flat()); $output = $backup; } } my @found = gather find-words(<ive lus inc>); .say for @found; # ive # ivelus # lus # lusive # lusiveinc # lusinc # lusincive # inc # incive