199302: Icon C clearly now...


    Icon is a high-level, general-purpose programming language that offers a broad range of string- and list-processing facilities. It also has a novel expression evaluation mechanism and allows an unusual degree of run-time flexibility.

    - Preface, The Implementation of the Icon Programming Language

And other massive understatements. Icon is a follow-on project to SNOBOL4, so its string-handling facilities are very powerful. Using unusual but intuitive subscript notation, Icon allows sub-strings to be extracted, examined, and inserted in a totally painless manner. Icon character sets allow trivial implementation of islower-style tests.

Icon also excels at higher-level data structures. Icon lists can be subscripted like C arrays. They can also be concatenated, and sub-lists can be treated much like sub-strings, above. Finally, Icon lists allow items to be pushed or popped at either end.

Icon sets support all the usual operations (intersection, union, etc.). Icon tables act much like AWK's associative arrays, save that the subscripts (keys, really) can be of any desired type. Icon records act much like C structs. Notably, any of these structures can have any of the others as members, allowing some very nifty combinations.

The "novel expression evaluation mechanism" is based on the notion that expressions can either succeed (returning a value) or fail. The expression !foo is a generator, returning successive items in (string, list, set, ...) foo. The statement every write(!foo) prints every value in foo, terminating quietly when no more elements remain. Icon functions can "suspend" (returning a value, but saving their state) an indefinite number of times before they finally "fail".

Icon syntax is clean and orderly, and encourages an open, readable coding style. The operators can get a bit baroque at times (e.g. ~===:=), but they follow a consistent pattern, so they are easy to figure out. A simple Icon version of cat(1) might look like:

    # simple "cat" program
    procedure main()
      every write(read())
    end
  

Icon is not well suited to the generation of nifty "one-liners". It lacks the built-in regular expression magic of awk, perl, and sed, relying on library functions to handle these tricks. On the other hand, it gracefully handles problems that are beyond the reasonable limits of awk and sed. The syntax is also much less baroque than that of perl, making Icon code substantially more pleasant (IMHO) to read. As for Icon's goals, let's turn back to the Griswolds:

    The focus of this book is the implementation of programming-language features that are at a high conceptual level - features that are easy for human beings to use as opposed to features that fit comfortably on conventional computer architectures. The orientation of the implementation is generality and flexibility, rather than maximum efficiency of execution. The problem domain is strings and structures rather than numbers. It is these aspects that set the implementation of Icon apart from more conventional programming-language implementations.

    - Introduction, The Implementation of the Icon Programming Language

So where is it?

As noted in last month's column (Network Resources), the archives for the Icon Project reside in ftp://cs.arizona.edu/pub/icon/. The archives contain implementations of Icon for several common operating systems (Acorn, Amiga, Atari, Macintosh, MS-DOS, OS/2, UNIX, and VMS). They also contain a wealth of clean, annotated sample code and a number of technical reports.

If you lack FTP access, don't despair. Contact the Icon Project in writing:

    Gould-Simpson Building
    Department of Computer Science
    The University of Arizona
    Tucson, AZ  85721 USA
  

or by telephone (602-621-8448, Fax -4246) and they will tell you how to obtain the current Icon distribution.

The Icon Project supports a large number of common UNIX variants. The configuration and test suite is very clean and well-documented, making installation quite painless. Should you be on an unusual platform, don't worry. Almost everything is built out of C code, so porting to a new platform is pretty trivial. If you get in trouble, the project staff are very good about helping out, and an active mailing list provides additional support.


This material was originally published in Rich Morin's column "The Internet Notebook" in UNIX
Review magazine (now known as Performance Computing magazine).

Send comments, inquiries, or trouble reports to webmaster@cfcl.com.

Copyright © 1993-1999 Rich Morin. All Rights Reserved.