Newsgroups: comp.lang.icon
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!maverick.ksu.ksu.edu!ux1.cso.uiuc.edu!midway!ellis.uchicago.edu!goer
From: goer@ellis.uchicago.edu (Richard L. Goerwitz)
Subject: Re: terrible code (2)
Message-ID: <1991Mar18.171946.28280@midway.uchicago.edu>
Sender: goer@midway.uchicago.edu (Richard L. Goerwitz)
Organization: University of Chicago
References: <9103181558.AA20389@uunet.uu.net>
Distribution: inet
Date: Mon, 18 Mar 91 17:19:46 GMT

In article <9103181558.AA20389@uunet.uu.net> nowlin@isidev.UUCP writes:
>    m := 0
>    while *(p := (s ? =!l)) > m do m := *p
>    return m + 1

Very clever.  Try matching each member of l, keeping a record of the
length of the match.  The longest match wins.

This sort of code does exactly what my code does.  Here's the problem.
Solution of the type exemplified above involve mindless interation
through the entire list, l.  I decided that it would be sensible to
write a little program that made this process deterministic.  I used
tables of tables to accomplish this.  Read a char, then see if the
char is in the lookup table.  Whatever strings begin with that char
become possible matches.  Then read another char.  Of the strings con-
sidered possible matches before, only those whose 2nd character matches
the one just read are possible matches, etc.

I added a cheat.  If at any time we run into "" (some string runs out
of chars), we remember that spot, and continue with the remaining
strings.  If nothing else matches beyond this point, we backtrack to
it and return the position we were at when we ran out of characters in
on of the strings.

Anyway, this is pretty much a deterministic process (with that one
cheat described immediately above).  It's slow as mud, though.  And
so your code, Jerry, while seemingly "dumb but elegant" turns out
better than mine!

There must be a way to do the kinds of things we're talking about here
in Icon, and do it with somewhat greater speed than the =!l approach.

-Richard
