#!/usr/local/bin/ici /* This program reads a list of words, 1 per line, from stdin, ** removes any redundancies, then outputs the remainders in ** alphabetic order. */ /* * This demonstrates ICI's collection types, set and array. The above * comment comes from the start of a 151-line C program included with * Phong Vo's CDT library. The CDT library is about the best container * library available for C. This program shows how much simpler ICI * is with its builtin types providing the facilities required to * easily model data. Of course the resulting program is slower than * the C but that is not too much of a concern for many applications * in this day and age where fast hardware is cheap. If performance * is a concern then the important parts can be coded in C and called * from ICI. Afterall only 10% or so of most programs is critical to the * performance of the program. * * Anyway, back to the program... */ /* * Form a set of the words of input. Assume each line is really a * separate word, otherwise we could use gettoken() to extract the * first token from the line or gettokens() to read the line and * pick off the first element of the returned array. ICI provides * some very useful input functions. */ words := set(); while (word := getline()) words[word] = 1; /* * Turn the set into an array so we can sort it. The ICI sort() * function sorts an array so we need one. We have to iterate * over the elements in the set and add them to an array, one * at a time as there is no builtin for doing this. */ tmp := array(); auto word; forall (word in words) push(tmp, word); words = tmp; /* * And finally output the sorted words */ forall (word in sort(words)) printf("%s\n", word);