home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / tests / general / wordcnt.icn < prev    next >
Text File  |  2001-05-02  |  572b  |  25 lines

  1. #
  2. #          W O R D   C O U N T I N G
  3. #
  4.  
  5. #  This program tabulates the words in standard input and writes the
  6. #  results with the words in a column 20 characters wide.  The definition
  7. #  of a "word" is naive.
  8.  
  9. procedure main()
  10.    wordcount(20)
  11. end
  12.  
  13. procedure wordcount(n)
  14.    local t, line, x, i
  15.    static letters
  16.    initial letters := &lcase ++ &ucase
  17.    t := table(0)
  18.    while line := read() do
  19.       line ? while tab(upto(letters)) do
  20.          t$<tab(many(letters))$> +:= 1
  21.    x := sort(t,3)
  22.    every i := 1 to *x - 1 by 2 do
  23.       write(left(x$<i$>,n),x$<i + 1$>)
  24. end
  25.