develooper Front page | perl.perl6.language | Postings from July 2006

Re: Containers

Thread Previous | Thread Next
Trey Harris
July 11, 2006 09:55
Re: Containers
Message ID:
In a message dated Tue, 11 Jul 2006, Aaron Sherman writes:
> But would it be reasonable to also provide a named-only parameter to
> each for that purpose?
> our List multi Container::each(Bool :$stop, Container *@containers)
> So that:
> for each(:stop, =<>; 1..*) -> ($line, $lineno) {
>   say "$lineno: $line";
> }
> would only iterate until one of the containers was exhausted (in this
> case, the filehandle).
> Should this be added? Should zip have the same modifier?

It sounds reasonable to me, but :stop reads badly.  Maybe C<:strictly>? 
Maybe it's not a function of a flag to each, but a marking that certain 
lists should be tapped non-exhaustively:

   for each(=<>; :with(1..*)) -> ($line, $lineno)

Where "with" is almost certainly the wrong word.  That way, you could 

   for each(@queue1; @queue2; :with(1..*)) -> $t1, $t2, $job_num {
       say "Running job #$job_num";
       $proc1.run_task($t1); # Can deal with $t1 being undef
       $proc2.run_task($t2); # Ditto with $t2

And you'll eat the rest of @queue1 or @queue2's elements even if they 
don't match up exactly.

This all makes me wonder if there's any problem with mixing and matching 
these loop modifying subs:

   for each(roundrobin(@queue1; @queue2); :with(1..*)) -> $task, $job_num {
       say "Running task {$}(#$job_no)";

I hope not.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About