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

Re: Hyper-operators and Underscore

Thread Previous
From:
Jeremy Howard
Date:
October 6, 2001 03:16
Subject:
Re: Hyper-operators and Underscore
Message ID:
001401c14e4f$b13c0c50$0d00a8c0@samantha
Erik Lechak wrote:
> 2)  RFC 082: Arrays: Apply operators element-wise in a list context
> (hyper operators)
> and
> 3)  Special variable representing index of array in foreach structure
> "$#" maybe (not in apocolypse3, I think)
>
Hi Eric. Thanks for your comments. Unfortunately it's a little early for
detailed consideration of vector and matrix operations, which will be
covered in more detail in a later Apocolypse. However, here's a couple of
pointers from the RFCs that may appear in some form in Larry's later
musings.

First, check out:
  http://dev.perl.org/rfc/207.html

This provides looping indices for multidimensional arrays. Please read RFCs
202-206 first though, since RFC 207 draws heavily on them.

Next, note that hyper-operators are a bit smarter than the behaviour you
indicate. Most notably, they 'broadcast' lower dimensionality structures to
the highest dimensionality structure. We're only up to 1-dim structures in
the Apocolypses so far, so for now that just means that
  @a = @b ^+ 1;
works as it should. This is a more interesting issue when, for instance,
broadcasting a vector across a matrix, but now I'm getting ahead of
myself...

Finally, note that there is an RFC which can simplify iteration through
lists n-at-a-time:
  http://dev.perl.org/rfc/90.html

So you can then pull the first element from each list with:
  my ($a,$b,$c) = merge(@a,@b,@c)



Thread Previous


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