From: rantapaa@s6.math.umn.edu (Erik E. Rantapaa)
Newsgroups: comp.lang.icon
Subject: Re: should I use ICON for a specific problem ?
Date: 9 Apr 92 01:34:35 GMT
Article-I.D.: s6.rantapaa.702783275
Organization: University of Minnesota

goer@ellis.uchicago.edu (Richard L. Goerwitz) writes:

>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:

Not wishing to get into a Perl vs. Icon flame fest, I would suggest that
you seriously consider using Perl.  Not only does Perl have many of the
features that you require, but it also comes with a program called 'a2p'
which converts awk programs to Perl.

>>1. "string-indexed" arrays should be available (nawk-syntax: array["string"])

+++ Perl has these so called 'associative arrays'.

>>2. multidimension arrays should be available   (nawk-synax:  array[1,2])

--- Perl loses here.  Only singly dimensioned arrays are supported, but
multi-dimensional arrays can be simulated, e.g. array["1,2"].

>>3. integer type variables should be available  (with #define AWKTYPE long ...)

000 Perl uses doubles to represent all numbers.  There is an 'int()' 
function to return the greatest integer function.

>>4. subroutines should be available

+++ Perl has 'em! (see note below)

>>5. same loops as for, do and while in C should be available (not the 
>>   same syntax is needed ...)

+++ Perl has loops with equivalents for 'continue' and 'break'.

>>6. total computer-readable documentation is needed (I don't want to buy a
>>   book of a thing, that maybe don't do it ...)

+++ Perl comes with lots of free documentation -- in texinfo format.

>>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).

Perl has its roots in the Unix utilities sed, ed, grep, sh and, yes, awk.
(Yes, yes is a Unix utility; no, it's not related to Perl :) My knowledge
of genealogical terminalogy is not that great, so maybe someone else can
fill in what relationship Perl, awk and Icon have with each other.

>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.

Perl arrays function for the most part just like awk's.

>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.

In general, Icon has better support for data sturctures than Perl does.
It's not real easy to implement 'recursive' data structures in Perl, although
it can be done (although usually a way is found to get around it.)

>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).

Icon wins with the arbitrarily large integers.

>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."

Perl has labels like C does.  Icon has more powerful subroutines, however.
They are, in fact, more like co-routines, something I wish Perl had.

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

>Question #6:  Online docs?  Answer:  Yes.  But it's so much easier just to
>get a book :-).

You can spend money for a book on Perl if you want to, too :)  It's
actually a very good reference manual, and it's crammed with a lot
of useful examples.

>-- 

>   -Richard L. Goerwitz              goer%ellis@uchicago.bitnet
>   goer@ellis.uchicago.edu           rutgers!oddjob!ellis!goer
--
Erik Rantapaa                              rantapaa@math.umn.edu