1 USING: kernel help.markup help.syntax sequences quotations ;
4 ARTICLE: "sets" "Set-theoretic operations on sequences"
5 "Set-theoretic operations on sequences are defined on the " { $vocab-link "sets" } " vocabulary. All of these operations use hashtables internally to achieve linear running time."
10 { $subsection all-unique? }
11 { $subsection duplicates }
12 "Set operations on sequences:"
14 { $subsection intersect }
16 "Set-theoretic predicates:"
17 { $subsection intersects? }
18 { $subsection subset? }
20 "A word used to implement the above:"
21 { $subsection unique }
22 "Adding elements to sets:"
23 { $subsection adjoin }
24 { $subsection conjoin }
25 { $see-also member? memq? contains? all? "assocs-sets" } ;
30 { $values { "elt" object } { "seq" "a resizable mutable sequence" } }
31 { $description "Removes all elements equal to " { $snippet "elt" } ", and adds " { $snippet "elt" } " at the end of the sequence." }
34 "USING: namespaces prettyprint sets ;"
35 "V{ \"beans\" \"salsa\" \"cheese\" } \"v\" set"
36 "\"nachos\" \"v\" get adjoin"
37 "\"salsa\" \"v\" get adjoin"
39 "V{ \"beans\" \"cheese\" \"nachos\" \"salsa\" }"
42 { $side-effects "seq" } ;
45 { $values { "elt" object } { "assoc" "an assoc" } }
46 { $description "Stores a key/value pair, both equal to " { $snippet "elt" } ", into the assoc." }
49 "USING: kernel prettyprint sets ;"
50 "H{ } clone 1 over conjoin ."
54 { $side-effects "assoc" } ;
57 { $values { "seq" "a sequence" } { "assoc" "an assoc" } }
58 { $description "Outputs a new assoc where the keys and values are equal." }
60 { $example "USING: sets prettyprint ;" "{ 1 1 2 2 3 3 } unique ." "H{ { 1 1 } { 2 2 } { 3 3 } }" }
64 { $values { "seq" "a sequence" } { "newseq" "a sequence" } }
65 { $description "Outputs a new sequence with each distinct element of " { $snippet "seq" } " appearing only once. Elements are compared for equality using " { $link = } " and elements are ordered according to their position in " { $snippet "seq" } "." }
67 { $example "USING: sets prettyprint ;" "{ 1 1 t 3 t } prune ." "V{ 1 t 3 }" }
71 { $values { "seq" "a sequence" } { "newseq" "a sequence" } }
72 { $description "Outputs a new sequence consisting of elements which occur more than once in " { $snippet "seq" } "." }
74 { $example "USING: sets prettyprint ;" "{ 1 2 3 1 2 1 } duplicates ." "{ 1 2 1 }" }
78 { $values { "seq" sequence } { "?" "a boolean" } }
79 { $description "Tests whether a sequence contains any repeated elements." }
81 "USING: sets prettyprint ;"
82 "{ 0 1 1 2 3 5 } all-unique? ."
87 { $values { "seq1" sequence } { "seq2" sequence } { "newseq" sequence } }
88 { $description "Outputs a sequence consisting of elements present in " { $snippet "seq1" } " but not " { $snippet "seq2" } ", comparing elements for equality."
90 { $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } diff ." "{ 1 }" }
94 { $values { "seq1" sequence } { "seq2" sequence } { "newseq" sequence } }
95 { $description "Outputs a sequence consisting of elements present in both " { $snippet "seq1" } " and " { $snippet "seq2" } "." }
97 { $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } intersect ." "{ 2 3 }" }
101 { $values { "seq1" sequence } { "seq2" sequence } { "newseq" sequence } }
102 { $description "Outputs a sequence consisting of elements present in " { $snippet "seq1" } " and " { $snippet "seq2" } " which does not contain duplicate values." }
104 { $example "USING: sets prettyprint ;" "{ 1 2 3 } { 2 3 4 } union ." "V{ 1 2 3 4 }" }
107 { diff intersect union } related-words
110 { $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } }
111 { $description "Tests if " { $snippet "seq1" } " and " { $snippet "seq2" } " have any elements in common." }
112 { $notes "If one of the sequences is empty, the result is always " { $link f } "." } ;
115 { $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } }
116 { $description "Tests if every element of " { $snippet "seq1" } " is contained in " { $snippet "seq2" } "." }
117 { $notes "If " { $snippet "seq1" } " is empty, the result is always " { $link t } "." } ;
120 { $values { "seq1" sequence } { "seq2" sequence } { "?" "a boolean" } }
121 { $description "Tests if both sequences contain the same elements, disregrading order and duplicates." } ;
125 { "seq" sequence } { "quot" quotation }
126 { "newseq" sequence } }
127 { $description "Maps a quotation onto a sequence, concatenates the results of the mapping, and removes duplicates." } ;