sets.extras: Initial checkin. Add setwise-xor word like setxor1d in numpy.

db4
Doug Coleman 2013-03-06 09:59:37 -08:00
parent fe9448533f
commit cadde9117c
4 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1 @@
Doug Coleman

View File

@ -0,0 +1,25 @@
! Copyright (C) 2013 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: help.markup help.syntax kernel sequences sets ;
IN: sets.extras
HELP: setwise-xor
{ $values
{ "seq0" sequence } { "seq1" sequence }
{ "set" set }
}
{ $description "Converts the sequences to sets and takes the element-wise " { $link xor } ". Outputs elements that are in either set but not in both." }
{ $example
"USING: sets.extras prettyprint ;"
"{ 1 2 3 } { 2 3 4 } setwise-xor ."
"{ 1 4 }"
}
{ $notes "Known as setxor1d in numpy." } ;
ARTICLE: "sets.extras" "Extra sets words"
"The " { $vocab-link "sets.extras" } " vocabulary is a collection of words related to sets."
$nl
"To take the element-wise xor of two sequences as if they were sets:"
{ $subsections setwise-xor } ;
ABOUT: "sets.extras"

View File

@ -0,0 +1,19 @@
! Copyright (C) 2013 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test sets.extras ;
IN: sets.extras.tests
{ { } }
[ { } { } setwise-xor ] unit-test
{ { 1 } }
[ { 1 } { } setwise-xor ] unit-test
{ { 1 } }
[ { } { 1 } setwise-xor ] unit-test
{ { } }
[ { 1 } { 1 } setwise-xor ] unit-test
{ { 1 4 5 7 } }
[ { 1 2 3 2 4 } { 2 3 5 7 5 } setwise-xor ] unit-test

View File

@ -0,0 +1,7 @@
! Copyright (C) 2013 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel sequences sets ;
IN: sets.extras
: setwise-xor ( seq0 seq1 -- set )
[ append members ] [ intersect ] 2bi diff ;