// file: mail5.rex // author: keller // purpose: development of a mailing list processor, step 5 // The problem is now extended as follows: If a word in 'lists' is not // the name of a list in db, then the word itself is included in the result. // select(items, db) creates a list of individuals in mailing lists named // in items, with no duplicates. If an item is not the name of a mailing // list, it is assumed to be an individual. select(items, db) = remove_duplicates( append(mappend(rest, keep((List) => member(first(List), items), db)), drop((Item) => member(Item, map(first, db)), items))); // The first argument to append creates the lists of the individuals in // items which are in mailing lists, by finding that list and keeping the // rests of those lists. // The second argument drops those items which name a list from the list // of items, so that a list of the items not naming a list is returned. test() = select(["cs-majors", "joe", "math-majors", "class of 00", "frank"], db); // built-in functions used: first, rest, member, keep, map, mappend, // remove_duplicates // db is the database of mailing lists; It is a list of lists. // Each list consists of the name of the mailing list, followed by // the individuals on the list. db = [ ["cs-majors", "mary", "john", "tom", "avi" ], ["math-majors", "alice", "tom", "franz", "yukio" ], ["class of 99", "mary", "tom", "yukio" ], ["class of 00", "john", "avi", "alice", "franz" ], ["cs-faculty", "george", "gwen", "prithi" ], ["math-faculty", "al", "gwen" ], ["curriculum-comm", "al", "prithi" ] ];