Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!LAGUNA.METAPHOR.COM!alex From: alex@LAGUNA.METAPHOR.COM (Bob Alexander) Newsgroups: comp.lang.icon Subject: Comment on longstr.icn Message-ID: <9103200028.AA02704@laguna.Metaphor.COM> Date: 20 Mar 91 00:28:02 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 48 Gee, this is fun. I have a couple of comments to throw into the frey. 1) Perhaps instead of the stop() if there is a problem with the arguments, a runerr() would be more consistent with the builtin string-analysis procedures -- "115: list, set, or table expected" would be reasonably appropriate, since the algorithm could work with tables too (records, too, for that matter, but that's probably a bit much). 2) Things could be simplified quite a bit by not messing with defaults for s, i, and j and letting Icon do the work by eliminating the string scanning. In this version, the m := -1 initial value can revert back to 0, since matching an empty string returns 1. So here's my entry in the series of suggestions. Somehow I can't help but wonder if I've missed something obvious -- but if not, do I get my name in the growing list of credits? :-) procedure longstr(l,s,i,j) local m # # Is l a list, set, table? # type(l) == ("list" | "set" | "table") | runerr(115,l) # # Find longest match()-ing string in l. # m := 0 # Attempt to match() each member in l (=!l). every m <:= match(!l,s,i,j) # Produce the length of each match that suc- # ceeds, and store its value in m iff it is # greater than m's current value. # # Return i + the length of the longest match. Fail if there was # no match (i.e. m still has its original value). # return 0 ~= m end -- Bob Alexander Metaphor Computer Systems (415) 961-3600 x751 alex@metaphor.com ====^=== Mountain View, CA ...{uunet}!{decwrl,apple}!metaphor!alex