Athanasius has asked for the wisdom of the Perl Monks concerning the following question:
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:
- Where are the Seq object(s) being created and used?
- I tried examining the contents of @dirs using say @dirs.perl;, but that had the same effect as uncommenting line B. Is there a way to examine the contents of @dirs (like using Data::Dump in Perl5) without introducing changes?
- Adding line B removes the error, but feels like a kludge. What is the correct way of writing this sort of code?
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, |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: [Perl6] Seq iterator already consumed
by choroba (Cardinal) on Jun 17, 2019 at 09:11 UTC | |
by Athanasius (Archbishop) on Jun 17, 2019 at 12:24 UTC | |
by duelafn (Parson) on Jun 17, 2019 at 13:36 UTC | |
by Athanasius (Archbishop) on Jun 19, 2019 at 06:51 UTC | |
by duelafn (Parson) on Jun 20, 2019 at 03:36 UTC | |
by karlgoethebier (Abbot) on Jun 17, 2019 at 18:21 UTC |