I only started learning Perl 6 within the last week, so please bear with me. :-)
I had a script working nicely, then I added another statement (line D in the code below) and received a run-time error message like this:
The iterator of this Seq is already in use/consumed by another Seq (you might solve this by adding .cache on usages of the Seq, or by assigning the Seq into an array)
From the documentation I gather that I have somehow created a Seq object and then attempted to iterate it a second time. But I don’t understand where or how the Seq object is being created and used.
I managed to pare down the code to the following SSCCE:
use v6; my @paths = data(); my @dirs.push: $_.split('/') for @paths; # A # @dirs.perl; # B say $_.join('/') for @dirs; # C my $depth = @dirs.map(*.elems).min; # D sub data { my $text = q:to/END/; /aardvark/bison/camel/dromedary /aardvark/bison/camel/dromedary/elephant END return $text.lines; }
Lines A, C, and D are all required to produce the error. Uncommenting line B removes the error (by caching, apparently, although I’m not sure exactly what is cached). So I have 3 questions:
In case it matters:
11:03 >perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. 12:14 >
Thanks,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to [Perl6] Seq iterator already consumed by Athanasius
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |