develooper Front page | perl.perl6.language | Postings from October 2001

Re: reduce via ^

Thread Previous | Thread Next
From:
Jonathan Scott Duff
Date:
October 10, 2001 14:04
Subject:
Re: reduce via ^
Message ID:
20011010160418.H17820@cbi.tamucc.edu
On Wed, Oct 10, 2001 at 01:27:35PM -0700, Colin Meyer wrote:
> On Wed, Oct 10, 2001 at 09:42:58PM +1000, Damian Conway wrote:
> >  
> >  John observed:
> > 
> >    > I just read Apocalypse and Exegesis 3, and something stuck out at me
> >    > because of its omission, namely using hyper operators for reduction.
> >    > 
> >    > $a ^+= @list;  # should sum the elements of @list
> 
> Does this mean that 
> 
> @a ^+= @b;
> 
> will add every value of @b to every value of @a?

That's what I'd expect it to do.  Well ... that's assuming you really
mean "each" where you said "every".  i.e.,

	my $i = 0;
	while ($i < length(@a) && $i < length(@b)) {
           @a[$i] += @b[$i];
        }

Just like I'd expect

	@a = @b ^=~ @patterns;

to be roughly equivalent to:

	my $i = 0; @a = ();
	while ($i < length(@patterns) && $i < length(@b)) {
	   push @a, (@b[$i] =~ @patterns[$i]);
	   $i++;
	}

-Scott
-- 
Jonathan Scott Duff
duff@cbi.tamucc.edu

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