[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Iternating over multiple lists






sub map4(&\@\@\@\@){

	local $[ = 0;

	my ($a,$b,$c,$d);
	my $i = 0;
	my $block = shift;
	my @r, @result = ();

	TOP:
	($a,$b,$c,$d) = ($$_[0][$i],$$_[1][$i],$$_[2][$i],$$_[3][$i++]);
	
	# adjust next line to suit
	defined $a or $defined $b or $defined $c or $defined $d or return @result;

	{
	 my @_ = ($a,$b,$c,$d);
	 @r=(&$block);
	}

	push @result, @r

	goto TOP;
};

Is that correct?  Is that what the discussion has gotten to so far?


Do we have variable-length prototypes, 
sub mmap(&\@+)
yet?

writing mmap(&@) to take a bunch of array references (which must
be explicitly referecned) woulsn't be that much trickier	



	$block = shift;
	foreach $i(@_){
		next if defined(@{$i});
		warn "mmaapp called with non-arrayref argument";
		return undef;
	};
	$i = $[;
	




}








Ronald J Kimball wrote:
> 
> On Thu, May 18, 2000 at 04:47:05PM -0500, David L. Nicol wrote:
> > Adam Sampson wrote:
> > >
> > > On Wed, Apr 12, 2000 at 05:54:19AM +0000, John Carter wrote:
> > > > > What perl needed to make the solution to this problem trivial (and
> > > > > elegant) is "multiple map" (or, if you rather "parallel map").  That
> > > > > is, imagine if you could do:
> > > > >
> > > > >    mmap {BLOCK} list1 list2 list3 list4
> >
> > I'm missing something.  What is this supposed to return
> > that
> >
> > map {BLOCK} (list1, list2, list3, list4)
> >
> >
> > or even, if they're all list references,
> >
> > map {[map {BLOCK} @$_]} (list1, list2, list3, list4)
> >
> >
> > doesn't?
> 
> Those both operate on a single element from a single list at a time.  The
> proposed "multi map" would operate on a single element from *each list* at
> a time.  If you had four lists, BLOCK would get four elements at once.
> 
> Ronald

-- 
                          David Nicol 816.235.1187 nicold@umkc.edu
                                drawn to the speed and performance

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe