On Fri, 1 Nov 2002, Ed Peschko wrote:

> I'm probably opening up a whole new can of worms here, but if we said
> that the following were both vector operators:
>
>       ^ == intersection operator
>       v == union operator
>
> then these could have potentially useful meanings on their *own* as set
> operators, as well as modifying other operators. For example:
>
> @a = (1,2,3);
> @b = (4,1,3);
>
> @a = @a ^ @b; # @a = (1,3);
> @a = @a v @b; # @a = (1,2,3,4);

Or is @a = (1,2,3,4,1,3) ?

So what happens with:

 @a = (1, 2, 3, 3);
 @b = (4, 3, 1, 3);

 @a = @a ^ @b; # @a = (1,3) ? @a = (1, 3, 3) ? element order?
 @a = @a v @b, # @a = (1, 2, 3, 4) ? @a = (1, 2, 3, 4, 4, 4, 1, 3) ?

Does the operand order change something?

The element order is significant in arrays, but not in hashes. And with
hashes, each key is unique. For a hash, these operators should be simpler.

 %a = ( 1 => 'a', 2 => 'b', 3 => 'c' );
 %b = ( 4 => 'A', 1 => 'B', 3 => 'C' );

And the operand order could be used to apply a "keep the values from the
left-hand side hash" rule:

 %a = %a ^ %b; # %a = (1 => 'a', 3 => 'c')
 %a = %b ^ %a; # %a = (1 => 'B', 3 => 'C')
 %a = %a v %b; # %a = (1 => 'a', 2 => 'b', 3 => 'c', 4 => 'A')
 %a = %b v %a; # %a = (1 => 'B', 2 => 'b', 3 => 'C', 4 => 'A')


(And notice how I avoided answering my own questions about arrays by
swiftly speaking of hashes... ;-)

-- 
 Philippe "BooK" Bruhat

 Few things in life are so dependable as the incompetence of those who know
 precisely what they are doing.   (Moral from Groo The Wanderer #5 (Pacific))

Reply via email to