On Mon, 15 Jul 2002, Karl Glazebrook wrote:

> In Apocalypse 2 Larry Wall wrote:
> 
> > RFC 082: Arrays: Apply operators element-wise in a list context
> >
> > APL, here we come... :-)
> >
> > This is by far the most difficult of these RFCs to decide, so I'm going 
> > to be doing a lot of thinking out loud here. This is research--or at 
> > least, a search. Please bear with me.
> <snip>
> > So the resolution of this is that the unmarked forms of operators will 
> > force scalar context as they do in Perl 5, and we'll need a special 
> > marker that says an operator is to be auto-iterated. That special 
> > marker turns out to be an uparrow, with a tip o' the hat to 
> > higher-order functions. That is, the hyper-operator:
> >
> >
> >     @a ^* @b
> 
> Excuse me, but *bletch*, - this is as ugly as sin. Especially when we 
> get into
> complex formulae. Imagine:
> 
> @solution =  (^-@b + sqrt(@b^**2 ^+ 4^*@a^*@c) ) ^/ (2^*@a);

That would not be very pretty, indeed.  It would also not be very 
efficient. (BTW, its b**2 - 4ac, not +  :)    A more efficient, pretty, 
and clear way would be like this:

        for @a; @b; @c; @s is rw -> 
            $a; $b; $c; $s {
                $s = (-$b + sqrt($b**2 - 4*$a*$c)) / (2*$a)
        }

> What is wrong with using @a * @b - the only reason I can think is to 
> preserve
> a backward compatibility which is not needed? 
> ...
> Why do we need to preserve @x as array length when you are proposing 
> @x.length ?

I see your point.  I went through a couple of my larger perl programs, and 
the only time I used arrays in numeric context was in the C-style for 
loop. 

I think the idea is the red flag.  If you have a 10000-element array, you 
wouldn't think a line like:

        $end = @array - 1

is going to take a long time and stick a big reference into $end.  And a 
lot of Perl 5 programmers would do that. I guess this is back on 
backwards-compatibility.  But do you see my point?

I wouldn't mind if this proposal was accepted, but I also think the hyper 
operator syntax is nice.  At least for what I'm doing, in which it's 
usually Yet Another shorthand for a C<foreach> (or now just C<for>) loop.

> If I was forced to write vector code like this I *WILL* give up on perl, 
> and resort to Numerical
> Python or IDL instead.

Well, I guess that will be your loss... especially when Python is 
assimilated by Perl. You will have nowhere to go :)

> appalled,
> 
>     Karl Glazebrook

attempting unappalment,
Luke

Reply via email to