develooper Front page | | Postings from September 2000

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

Thread Previous | Thread Next
September 8, 2000 20:34
Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context
Message ID:
Nathan Wiger wrote:
> > 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.

I disagree. You end up with a situation where some

   @a * @b;

are in scalar context, some not. And what happens when you say

   @a = (1,2,2);
   @b = tie Matrix (1,2,3);


Who wins?

From the user point of view a 1D multi-dim array will look just the same
as a normal perl list in *all* respects in a would-be perl6. I bet money
that users will be highly confused if some arrays enforce scalar context
in such operations, others don't. It is *much* clearer to have a clear
break with perl5 in this respect (even if code needs to be rewritten).

A p52p6 could replace all occurences of @a*@b with


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