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

Re: Containers

Thread Previous | Thread Next
From:
Trey Harris
Date:
July 11, 2006 09:55
Subject:
Re: Containers
Message ID:
20060711092029.D21435@bowser.eecs.harvard.edu
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 
write:

   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 {$task.id}(#$job_no)";
       $task.run(:$job_num);
   }

I hope not.

Trey

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About