develooper Front page | perl.perl6.language.data | Postings from September 2000

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

Thread Previous | Thread Next
From:
c.soeller
Date:
September 8, 2000 20:34
Subject:
Re: RFC 82 (v3) Arrays: Apply operators element-wise in a list context
Message ID:
m13Xbmv-002IJwC@csnote.mph.auckland.ac.nz
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);

   @a*@b;

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
scalar(@a)*scalar(@b).


  Christian

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