Computer Languages A to Z: Icon

by Gary L. Ratliff Sr. (eronstuc)

The Icon programming language was invented by the same gentleman who invented SNOBOL. Many people mistakenly visit its web site thinking that this is a tool to help them design icons! Dr. Ralph E. Griswold stated in his book, "The Icon Programming Language, 3rd Edition," that the word does not stand for anything in particular. However, this was designed to be a language which would make the development of computer programs easier for the programmer.

Icon was written in the C computer language, which was discussed in the Sept 2009 issue of this magazine. The language is in the public domain and is available from the University of Arizona. The web site will contain versions for Unix, BSD, Mac, Windows, 32 and 64 bit Linux, and some other computer platforms. What we shall do is create a directory in /home named Icon, and store the files which we download there. The main site for information on the Icon programming language is at the University of Arizona. Their Computer Science Department has won several awards for being one of the very best in the nation.

Unfortunately, Dr. Griswold passed away in 2006. There is a memorial web site established in his name. The information on Icon may be obtained from These are the files which I placed in my home/gary/icon folder: linux.v943.tgz (which is reached from the Unix link on the main page.) Now go on over to to obtain some starting documentation to learn to program using Icon. These are all available in pdf form: The Icon Programming Language 3rd Edition, Graphics Programming in Icon, The Implementation of the Icon Programming Language, and The Icon Handbook. This should keep you busy learning some of the features of this language, but first we will need to install and make the system usable on our PCLinuxOS Systems. For this step, we will become and remain root during the next several steps:

Establishing a Working Environment for Icon

What we are going to do is follow the recommendation of the developers of the language, as found in the README file found in the linux.v943.tgz file, and this system will be installed in /opt. Once this has been done, we will create several symbolic links to an area on the default PATH so that the system will load on command. And finally, we will make it so that the supplied man pages may be loaded automatically. Now that we have established our goals, here are the commands to accomplish these items, which shall be performed from a terminal.

<enter the root password>
mv /home/gary/icon/linux.v943.tgz /opt
cd /opt
tar -zxvf linux<tab>
mv linuz.v943.tgz /home/gary/icon
mv icon.v943 icon
cd icon/man/man1
bzip2 icon.1
bzip2 icont.1
mv *bz2 /usr/share/man/man1/
cd /usr/local/bin
ln -s /opt/icon/bin/icon icon
ln -s /opt/icon/bin/icont icont
ln -s /opt/icon/bin/iconx iconx
ln -s /opt/icon/bin/vib vib

Once the exit command has been given, you revert to being a normal user and can issue commands without worrying about destroying the system should you make a silly typing error. The files which make up the Icon language system now reside in their preferred location: /opt/icon, and under this system we find the directories: /bin, /doc, /lib and /man, which contain the usual items found in directories with these names. However, the manual pages are made up of bzipped files, which are located in the /usr/share/man structure. So before we performed a few operations on the files in /opt/icon/man/man1, we could have only received a no manual page exists for icon, and the same for the item icont. We are now ready to begin creating icon programs.

Interestingly enough, a file which is edited in emacs, which has an .icn extension, may be compiled from within emacs (unless it of course has user input). Just as there is a Fortran menu item for one with a .f extension, so too will there be found an icon menu item for emacs. You get the drill. The very first program to be developed is the infamous Hello World program. So from a terminal, issue the command: emacs hello.icn and enter the following code into the editing buffer:

procedure main()
  write(“Hello World”)

That's it, short and sweet. So first, save the buffer. As this requires no user input, we are ready to compile. So click on the tools menu item and select compile. Then backspace over the make -k item which will appear, and replace it with the command :

icon hello.icn

A message will appear in the compilation buffer telling you that the operation was a success, and the message "Hello World" will be displayed. Next, we will show you a simple program to compute the powers of the first twenty five integers for the radix from 1 to 5. And, we are going to display the data in a nicely formatted report. A picture is said to be worth a 1000 words, so here is a snap of the program and its output as entered and compiled in emacs:

Since the picture is a little small here is the text of the program which I called lineup.icn:

$define Limit 25

procedure main()
  write("   pwr   square   cube    quad    quid")
  every i:= 1 to Limit do {
    write(right(i,5), right(i^2,8), right(i^3, 8), right(i^4, 8), right(i^5,8))

Features in Icon not found is other languages

Now would be a good time to introduce some of the features which seem to be unique to the Icon language. The first item, which I had never heard about, is an item called cset. This is mentioned quite a bit, however. What it means is seemingly taken for granted. Essentially, a cset is a set of all the characters within a given string. Now a set is defined as only containing one of each type item. So, if a string contains two or more of the same letter only one would be included in the cset. Also the items are arranged in order. The upper case letters are before the lower case items and numbers are before letters. So the cset of "hello" would be "ehlo." The cset of "Hello" would be "Helo," as this has an upper case H. It is easy to learn the cset of an item by casting this into a main procedure and compiling it in emacs.

For example: A := cset(“My name is Gary”); write(A) would produce the output: Gmaeimnrsy. As you might expect, these raise hell with the spell checkers.

The execution of conditional statements is based on the concept of success or failure. An item which might have several answers may be suspended once the first success if found, and then continued after this to go on to find other answers. When all possible answers have been found, it would then fail.

Also many of the symbols are used in an unconventional manner. This makes the reading of the manuals very important to gain any kind of understanding of what is going on in a program. A really fast introduction to the language was found in a set of slides presented as a course in Icon by Professor Mitchell.

A Little Bit of Graphics Programming

In the doc section, you should find some html pages. These may be launched from a terminal by entering firefox xyz.htm from within the doc folder. The file index.htm will present a flle for use in finding other areas of interest. In any event, there is a simple introduction to the graphics facilities. To create a window, you use: WOpen(“size=400,300”). Then certain attributes of the window, such as foreground color and backgroundm may be defined. The function WDone() prevents the window from closing until the user enters Q or Control + C to terminate the program.

Here are some screen shots of the output of some of the graphics programs:


The main Icon library at the university of Arizona contains some remarkable programs, and every one I have downloaded seems to indicate from the start that these are in the public domain. There is bj.icn, which plays a game of black jack. Puzzle.icn generates word game puzzles. And for chess fans, there is krieg.icn, which plays the game Kriegspiel. This is a version of chess in which neither player sees the board. The player asks questions to learn if there are any captures available. The computer acts as the referee, and will also volunteer to play the role of an opponent named "auto."

Auto does not play a very good game of chess. Once the game is over, the computer shows you that the score of the game has been saved in a file in the /tmp directory. Since neither player knows what the other is doing, the object would be to quickly set up a known mate on the vulnerable KB7 square and hope that opponent has not developed and castled, so as to cover KB7 with a rook. Here is the score of the short first game I played vs auto:

Kriegspiel game begins Monday Sept. 7, 2009 8:45 pm
gary  auto
Pe2e4 Pc7c6
Pd2d4 Pg7g5
Ng1f3 Pd7d5
Nf3e5 Pd5e4
Bf1c4 Bc8h3
Result: 1-0
Kriegspiel game ends Monday Sept. 7, 2009 8:57 pm

I hope that this is enough to whet your appetite for learning more about the use of the Icon Programming Language. As you have learned, there is a vast amount of material available, and most of it is in the public domain. There are also other offshoots from Icon. Noteworthy are Idol and Unicon. These are efforts to introduce the concept of OOP into icon. The Idol is an Object Oriented set to be used with Icon as a pre-processor, while Unicon is a full Object Orientated version of Icon developed by Clinton L. Jeffery.

I have also received a message from Greg Townsend, now retired, that Icon is in active use at the University of Arizona. I think that this language could easily be added to your tool kit of programming languages.

Answers to Mark Szorady's Double Take:
(1) Turtle arm higher; (2) Computer monitor smaller; (3) Seat post missing; (4) Table different; (5) “Dang” changed to “Darn”; (6) Cabinet knobs lower; (7) Drawer missing.