Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #46202
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Set |
| Date | 2016-03-25 06:37 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nd2mbo$d7q$1@dont-email.me> (permalink) |
Set creation Test m ? S -- "m is an element in set S" A ? B -- union; a set of all elements either in set A or in set B. A n B -- intersection; a set of all elements in both set A and set B. A \ B -- difference; a set of all elements in set A, except those in set B. A ? B -- subset; true if every element in set A is also in set B. A = B -- equality; true if every element of set A is in set B and vice-versa. OCaml: module SS = Set.Make(String);; let s1 = SS.of_list ["foo"; "bar"; "of"; "in"; "on"; "over"; "anent"; "under"; "way"] ;; let s2 = SS.of_list ["foo"; "on"; "under"; "way"; "sway"; "swept"; "link"];; let s3 = SS.of_list ["bar"; "over"; "under"; "way"] ;; SS.mem "anent" s1;; ===> true SS.elements (SS.union s1 s2);; ===> ["anent"; "bar"; "foo"; "in"; "link"; "of"; "on"; "over"; "sway"; "swept"; "under"; "way"] SS.elements (SS.inter s1 s2);; ===> ["foo"; "on"; "under"; "way"] SS.elements (SS.diff s1 s2);; ===> ["anent"; "bar"; "in"; "of"; "over"] SS.subset s3 s1;; ===> true SS.equal s3 s2;; ===> false How much easier would this be in ANS Forth? -- Use this [sword] for me, if I rule well; if not, against me. --- Trajan "If a government uses the instruments of power in its hands for the purpose of leading a people to ruin, then rebellion is not only the right but also the duty of every individual citizen."
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Set "WJ" <w_a_x_man@yahoo.com> - 2016-03-25 06:37 +0000
csiph-web