develooper Front page | | Postings from September 2000

Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context

Thread Previous | Thread Next
Nathan Wiger
September 8, 2000 19:39
Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context
Message ID:
> This RFC proposes that operators in a list context should be applied
> element-wise to the elements of their arguments:
>   @d = @b * @c;   # Returns (2,8,18)
> If the lists are not of equal length, an error is raised.

I've been watching this RFC for a while. I would hesitate to change the
default behavior of * and other operators in so radical a sense,
especially since it would create unexpected error conditions. I think
these operations should remain scalar.

However, we need a means to do what you're after, definitely. I would
recommend you check out RFC 200, just posted, which proposes massive tie
changes that would allow for integrated data, function, and operator
overloading. From the RFC:

   tie My::Matrix @a;         # tie @a to $obj
   @c = @a + @b;              # @c = $obj->ADD(@b);
   $a[0] = 4;                 # $obj->STORE(0, 4);
   @d = @a * @b;              # @d = $obj->MUL(@b);

The idea would be operator and data overloading is completely integrated
with tie, based on the concept of polymorphic objects. As such, you
could create native PDL classes that would allow @a * @b to do what you

Otherwise, you have to decide if @a * @b should be element-wise, a
cross-product, a vector, or ??? I just think it's a can of worms that's
going to result in a set of arbitrary decisions, which in the the end
makes less sense than having these contexts remain scalar by default.


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