From: goer@ellis.uchicago.edu (Richard L. Goerwitz)
Newsgroups: comp.lang.icon
Subject: Re: should I use ICON for a specific problem ?
Date: 6 Apr 92 16:31:24 GMT
Reply-To: goer@midway.uchicago.edu
Organization: University of Chicago Computing Organizations

zrzm0111@helpdesk.rus.uni-stuttgart.de (MUFTI) writes:
>
>I wrote a long nawk-file for a machine where no awk-compiler is available.
>Now I'm searching for a language with the following spezifications:
>
>1. "string-indexed" arrays should be available (nawk-syntax: array["string"])
>2. multidimension arrays should be available   (nawk-synax:  array[1,2])
>3. integer type variables should be available  (with #define AWKTYPE long ...)
>4. subroutines should be available
>5. same loops as for, do and while in C should be available (not the 
>   same syntax is needed ...)
>6. total computer-readable documentation is needed (I don't want to buy a
>   book of a thing, that maybe don't do it ...)
>
>Should I use ICON for this ?

Awk actually has some of its roots in SNOBOL.  Nawk is, naturally, derived
from awk.  Likewise, Icon is derived (in part) from SNOBOL.  That makes Icon
nawk's uncle.  Of course, their two respective branches of the family don't
see each other much.  Oddly, though, it turns out that Icon and nawk are also
related on another side of the family, through granny Algol (Icon married
into this family some time after leaving home).

Down to business.

Your first question deals with string-indexed arrays.  Icon has these.  The
syntax is like awk's, and the semantics are similar.  You can subscript using
a value of any type.  Unlike awk, that type can include the null value.  One
big difference between awk and Icon is that the arrays must be initialized
explicitly.  They don't just spring into existence.  Also, awk arrays don't
correspond to a single data type in Icon.  For the type of thing you want to
do in question #1, Icon has hash tables.  We call them "tables."  They are
fast, and use a dynamic hashing algorithm, so that they are pretty smart in
how they use memory.

The second question you ask concerns multidimensionality.  In fact, you can
have a table of tables, and do things like array["hello"]["goodbye"].  You
can also use lists, which are more akin to their LISP counterparts than to
awk tables.  To get a multidimensional effect there, you use lists of lists,
and write array[1][1].  Lists in Icon aren't homogenous series' of data ob-
jects mapped into linear address space (as they are in, say, C).  They can
hold objects of any type.  So in fact subscripting is not a trivial opera-
tion in the underlying implementation, although to you the programmer it is
very simple and transparent.

You ask whether Icon has integer variables in question #3.  The answer is
"yes, there is an integer data type."  Integers in Icon can be arbitrarily
large in most cases, though, so the underlying implementation doesn't cor-
respond to a machine register-width object.  Of course, this doesn't matter
to you, the programmer.  So yes, Icon does have integers (and floating
point numbers as well).

Question #4:  Does Icon have subroutines?  If by this you mean that you can
define your own procedures, then yes.  If you mean, "does it let you use
labels," then the answer is "no."  Icon, on the surface, looks quite a bit
like an Algolish language.  In fact, Pascal programmers have little trouble
using it right off (although some never let go of the idea that Icon is a
cut-down Pascal, and never really get the hang of string scanning and goal-
directed evaluation).

Question #5:  Do, while loops?  Answer:  Yes.

Question #6:  Online docs?  Answer:  Yes.  But it's so much easier just to
get a book :-).  I personally just despise staring at a CRT when I could
be reading a properly typeset book.  If you absolutely insist on reading
the docs online, the Icon distribution includes a full documentation set.
A lot of their reports are packed in both ASCII and Postscript format, so
you can print the stuff up if you want.

I hope this helps.  Your query was interesting.  And your English, I might
add, is *perfect*.  At one point, you placed a comma before a restrictive
clause.  That was the only time it occurred to me that you might not be a
native speaker.

I hope this helps.

-- 

   -Richard L. Goerwitz              goer%ellis@uchicago.bitnet
   goer@ellis.uchicago.edu           rutgers!oddjob!ellis!goer
Newsgroups: comp.lang.icon