to me , this discussion approaches the conclusion that 
^[]  and v[] are *just* another operators with their own behavior  
that accept as ( optional ) argument a Code reference . 

to follow the beautifull philosophy  of perl6 --  "A is just B" we can
say ( following Larry Wall ) 
 
   ...
 >     A Perl5 magic is just a property.
 >     A Perl5 attribute is just a property.
 >     A block is just a closure.
 >     A control structure is just a subroutine that can call closures.
  ... 
(maybe...)
       A "for" loop is *almost* a subroutine that can call closures .  
       A vector operation  is just a ( cryptographic ) "for" loop 
         with one or two input streams and <op> name inside brackets 
         as a closure. 

so it is just a function  : 

sub infix:^[] ( Code &op :  Array @a , Array @b   
        ) is parsed /^[ <op> |  \[<op>\] ]/  
             { 
                my @inds = union( @a.keys, @b.keys); 
                return for @inds { 
                        &op ( @a[$_] , @b[$_] ) ;
                }
         }

sub infix:v[] ( Code &op :  Array @a , Array @b   
        ) is parsed /^[ <op> |  \[<op>\] ]/  
             { 
                my @inds = intersection( @a.keys, @b.keys); 
                return for @inds { 
                        &op ( @a[$_] , @b[$_] ) ;
                }
         }

or maybe 

sub infix:^[] ( Code &op :   Array @a , Array @b  
        ) is parsed /^[ <op> |  \[<op>\] ]/ 
         {
                return for @a ; @b -> ($x is rw ; $y is rw ) { 
                        &op ( $x , $y ) ;
                }
         }

sub postfix:^[] ( Code &op :   Array @a   
        ) is parsed /^[ <op> |  \[<op>\] ]/ 
        { for @a -> $x is rw &op( $x ) }  
....

and analogous things for v[] . and this can be prefix, infix, postfix
; and each argument can be $a, @a, %a ; so it is a multimethod. 

in that case the vectorization is *compleatly* orthogonal to the
details of op and we even can have something like 

@a ^[{ $^a > $^b ?? 1 :: ($^a,$^b) := ($^b,$^a) }]  @b  


arcadi 

Reply via email to