develooper Front page | perl.perl6.language | Postings from November 2002

vectorization (union and intersection operators)

Thread Next
From:
Ed Peschko
Date:
November 1, 2002 12:04
Subject:
vectorization (union and intersection operators)
Message ID:
20021101120110.A7647@rama.comp.pge.com
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);

ie @a = @a ^ @b; means

grep($MARK{$_}++, @a);
for @b { push (@result, $_) if ($MARK{$_} && !$MARK2{$_}++); }
@a = @result;

----

@a = @a v @b; means

grep( $MARK{$_}++, @a );
@result= @a;
for @b { push (@result, $_) if (!$MARK{$_}++) }

----

I know that this is far more useful behavior than the currently proposed meaning
of @a ^= @b... even though if its a little off kilter with the other meanings:


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

@a ^+= @b;  # (5,3,6);
@a v+= @b;  # (5,3,6,5);

etc. etc.


Ed

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