Department of Computer
Science The University of Arizona Tucson, Arizona IPD252a April 8,1996 http://www.cs.arizona.edu/icon/docs/ipd252.htm |
The Icon Programming Language, second edition, Ralph E. Griswold and Madge T. Griswold, Prentice-Hall, Inc., Englewood Cliffs, New Jersey, 1990. 365 pages. ISBN 0-13-447889-4.This book is available from the Icon Project at The University of Arizona.
Icon
Overview
on the distribution disk). Features that have been added
to Icon since the book was written are described in IPD236 [2] (Icon
Version 9
on the distribution disk). These technical reports, together
with this document (MPW Icon on the distribution diskette), provide enough
information to write and run simple Icon programs. Persons who intend to
use Icon extensively, however, will need the book.Existing
icon folder
choice. If this is your first Icon, select New
icon folder
.MPW Shell
, insert
the MPWIcon
disk (the distribution disk) into a disk drive
and enter the command:
The following items will be installed:MPWIcon:Installicon
Icon
folder (or other folder designated during the installation
process):
In your MPW folder:Tools icont The Icon translator and linker iconx The Icon interpreter Scripts IconMPWTool Converts an icode file to a stand-alone MPW tool. Other icon.help MPW-style help files for Icon.
The installation script will attempt to delete obsolete Version 7.0 (or earlier) files if it finds them. Those files areUserStartup°Icon Performs MPW initialization for Icon.
itran
, ilink
,
iconm
, iconx.hdr
, and bin
(the folder
and its contents). If you want to save these files, move them to a disk
or another folder before installation.Cancel
button. Installation can be restarted from the beginning
with no adverse consequences.UserStartup
file (in the MPW folder):
The ° character is option-8 (bullet). This requirement is discussed in more detail in section 9 of this document. The additional line is not necessary for MPW Version 3.0 and later.Execute UserStartup°Icon
.icn
. Such
files should be plain text files (without line numbers or other extraneous
information). The translator/linker program icont
produces
an executable icode file. For example, an Icon program in the file prog.icn
is translated and linked by
The result is an executable icode file with the nameicont prog.icn
prog
.
Icode files produced by MPW Icon behave identically to MPW tools, and thus
are invoked by entering their file names. The icode file just created can
be run by
Use of the suffix .prog
icn
in the icont
command is
optional. For example, it is sufficient to use
icont prog
icont
will supply the .icn
suffix if no suffix
is entered.
Samples
.
hello.icnThis program prints the Icon version number, time, and date. Run this test as
icont hello hello
kross.icnThis program prints all the ways that two words intersect in a common character. The filekross.dat
contains typical data. Run this test as
This program prints the "meandering strings" that contain all subsequences of a specified length from a given set of characters. Run this test asicont kross kross <kross.dat meander.icn
If these tests work, your installation is most likely correct -- you have a running version of Icon!icont meander meander <meander.dat
icont
translator/linker supports a variety
of options that may be useful in special situations. There also are several
aspects of execution that can be controlled with environment variables.
These are listed here. If you are new to Icon, you may wish to skip this
section on the first reading but come back to it if you find the need for
more control over the translation and execution of Icon programs.
runs the icode fileprog text.dat log.dat
prog
, passing its main procedure a list
of two strings
These arguments might be the names of files that["text.dat","log.dat"]
prog.icn
uses.
For example, the main procedure might begin as follows:
procedure main(a) in := open(a[1]) | stop("cannot open input file") out := open(a[2],"w") | stop("cannot open output file") ...
icont
can accept several Icon source
files at one time. When several files are given, they are translated and
combined into a single icode file whose name is derived from the name of
the first file. For example,
translates and links the filesicont prog1 prog2
prog1.icn
and prog2.icn
and produces one icode file, prog1
.-c
option is given to icont
, only translation
is performed and intermediate ucode files with the suffixes .u1
and .u2
are kept. For example,
leavesicont -c prog1
prog1.u1
and prog1.u2
, instead of linking
them to produce prog1
. (The ucode files are deleted unless
the -c
option is used.) These ucode files can be used in a
subsequent icont
command by using the .u1
name.
This avoids having to translate the .ic
n file again. For example,
translatesicont prog2 prog1.u1
prog2.icn
and links the result with the ucode files
from a previous translation of prog1.icn
. Note that only the
.u1
name is given. The suffix can be abbreviated to .u
,
as in
Ucode files also can be added to a program when it is linked by using link declarations in Icon source programs as described in [2].icont prog2 prog1.u
-s
option. Normally, both informative messages
and error messages are sent to standard error output.-o
option, followed by
the desired name. For example,
produces the icode file namedicont -o probe prog
probe
rather than prog
.-
signifies the use of standard input as a source file. In this case, the
ucode files are named stdin.u1
and stdin.u2
and
the icode file is named stdin
.&trace
has an initial value of 0. The -t
option to icont causes &trace
to have an initial value
of -1 when the program is executed. For example,
causes tracing to occur whenicont -t prog
prog
is run.-u
to icont
causes warning messages
to be issued for undeclared identifiers in the program. The warnings are
issued during the linking phase.
Region sizes expand if more space is needed, but they never shrink.
STRSIZE
(65000)- This variable determines the size, in bytes, of the initial region in which strings are stored. If additional string regions are needed, they may be smaller.
BLKSIZE
(65000)- This variable determines the size, in bytes, of the initial region in which Icon allocates lists, tables, and other objects. If additional block regions are needed, they may be smaller.
COEXPSIZE
(2000)- This variable determines the size, in 32-bit words, of each co-expression block.
MSTKSIZE
(10000)- This variable determines the size, in words, of the main interpreter stack.
STATSIZE
(20480)- This variable determines the size, in bytes, of the static region in which co-expressions blocks are allocated.
STATINCR
(calculated)- This variable determines the size of the increment used when the static region is expanded. The default increment is one-fourth of the initial size of the static region.
TRACE
(undefined)- This variable initializes the value of
&trace
. If this variable has a value, it overrides the translation-time-t
option.
NOERRBUF
(undefined)- If this variable is set,
&errout
is not buffered.
icont
supports the Commando facility of MPW. If the icont
command is executed via option-enter (instead of just enter),
or if icont
... is executed (icont
followed by
the ellipsis character, option-;), a dialog box will come up that
allows specification of all options permissible as command line parameters
to icont
. (The option-enter method of invoking Commando
is available only with Version 3.x of MPW and later). Since the dialog box
has "prompts" for most of the available options, it is an alternative
to using the manual or on-line help to remember options that are infrequently
used.IPATH
environment variable, which specifies where the
linker should search for library modules referenced in link declarations,
is a comma-separated list of directory (folder) names (just like the Commands
shell variable (this differs from most versions of Icon, which use a space-separated
list). The directory names must have a colon as the last character, as is
the MPW convention.ihelpIhelp
is an alias set up byUserStartup°Icon
that invokes the MPW help system.
icont
or an Icon program
can run in the background under the Finder (or MultiFinder for pre-System-7).icont
and during execution of Icon programs. During Icon
garbage collections, the cursor changes to the wristwatch shape.iconx
, must be installed
for Icon programs to run. MPW Icon now has the facility to bundle the interpreter
and icode file into a single Macintosh file, giving it the appearance and
functionality of normal non-interpreted MPW tool. Of course, since it contains
the interpreter, it is some 150K bytes larger than its corresponding icode-only
file. This feature is useful for creating MPW tools to be run on systems
that do not have MPW Icon installed. To convert an icode file to a stand-alone
tool, execute
IconMPWTool icode-file-name
File x.icn; Line 2 # "b": missing semicolon or operatoris a valid MPW command that will open the filex.icn
and select line 2. In a few cases, only a portion of the message is executable and must be selected.
open(filename,"w"
))
are MPW text files; that is they have the same type and creator as files
created within MPW: type = 'TEXT'
and creator = 'MPS
'. Therefore their icons in Finder windows are the same as for MPW
text files, and double clicking the icon invokes the MPW Shell to edit the
file.'TEXT'
, creator = 'UCOD'
.
Since they are human-readable text files, the type of 'TEXT'
makes them accessible to text editors (such as MPW Shell). The type 'UCOD'
causes them to have a generic document icon, rather than the MPW Shell text
file icon, to help distinguish them from Icon source files and other "normal"
text files.\n
and carriage return \r
have their usual values reversed in MPW Icon. This practice is "inherited"
from MPW C. The codes are reversed because the new line code used in Macintosh
text files is the carriage return (rather than the line feed as used by
UNIX), and will not likely cause any problems. Nonetheless, subtle effects
could be introduced, such as image(string('\n\r'))
producing
"\n\r"
on UNIX systems and"\r\n"
on Macintoshs.NoLineFlush
:
It is recommended thatSet NoLineFlush 1 ; Export NoLineFlushNoLineFlush
be used only when the additional speed is especially advantageous, since it often creates confusing output.
ICONCORE
environment variable, which causes a core
dump on error termination in many implementations of Icon, simply causes
an abort in MPW Icon. The only apparent difference between an abort and
a normal termination in the MPW environment is that a sequence of MPW commands
will terminate if a program aborts, regardless of the setting of shell variable
Exit
.the value ofwrites("How many?") # writes() outputs no new line character n := read()n
will contain the text"How many?"
followed by the entered text. The problem can be corrected by causing input strings to be on lines by themselves:
write("How many?") # write() outputs a new line character n
:= read()
UserStartup°icon
UserStartup
file, UserStartup°Icon
.
This change complements the change in MPW 3.0 to automatically execute all
files having names beginning with UserStartup°
as MPW
initializes upon startup. If you are running under an older version of MPW,
insert the command
into yourExecute UserStartup°IconUserStartup
file.
-m
option to icont
(for macro preprocessing)
is not implemented.-x
option to icont
(for automatic execution
after translating/linking) is not implemented.system()
is not supported."p"
option.
delay()
built-in function is now implemented.
Commando dialog box support foricont
.
Background running under MPW 3.0.
Spinning beachball cursor.
Wristwatch cursor during garbage collection.
On-line help facility.
Ability to create stand-alone MPW tools.
Error messages more MPW-like than in older versions.
Window I/O is line-buffered by default -- seeNoLineFlush
option in section 7.
File type and creator of created files is same as MPW text files (type and creator were null in older versions, making it difficult to edit them).
File type of ucode files is set to'TEXT'
, for easy viewing with text editors.
Changes in method of specifying total Icon memory allocation (IconSize
).
The-x
option oficonx
has not been supported by MPW Icon since Version 7.5. Its burden to the MPW implementation outweighs its utility.
File hierarchy changes are nil since Version 7.5, but there are some significant changes from earlier versions. Thebin
folder was done away with for Version 7.5. The Icon tools icont and iconx now reside in theIcon
folder in the default organization for MPW Icon. Thebin
folder used to hide a number of files that are no longer needed, namelyitran
,ilink
,iconm
, andiconx.hdr
. As with all implementations of Icon since Version 7.5, the translator(itran
), linker (ilink
), and control program (icont
) have been combined into a single program (icont
). Besides reducing the number of files needed to work with Icon, other benefits are gained such as increased speed of translation and linking, reduced disk space requirements, and generally simpler management of the Icon system.
IconBin
in previous
versions.ICONSIZE
is no longer needed. The other iconx
region-allocation environment variables (BLOCKSIZE
, STKSIZE
,
etc.) are still available to tune initial region allocation.
Trouble
Form???
on the distribution disk) and sent to
Icon ProjectIf a program is involved, enclose it and any relevant data on a disk.
Department of Computer Science
The University of Arizona
P.O. Box 210077
Tucson, AZ 85721-0077
U.S.A.
(520) 621-6613 (voice)
(520) 621-4246 (fax)
icon-project@cs.arizona.edu
An Overview of the Icon Programming Language;
Version 9, The Univ. of Arizona Icon Project Document IPD266,
1995.