Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uwm.edu!bionet!agate!ucbvax!isidev.UUCP!nowlin From: nowlin@isidev.UUCP Newsgroups: comp.lang.icon Subject: Re: partial input ... Message-ID: <9104111325.AA08584@relay1.UU.NET> Date: 11 Apr 91 13:25:47 GMT Article-I.D.: relay1.9104111325.AA08584 Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 69 I know I should resist but it's like a challenge. I just can't let a verbose Icon program go by without wanting to terse it up. I think of Icon as making it easier on me as a programmer. If Icon is going to do all this work for me why not let it? That's only partly rhetorical. Anyway, what follows contains a terser version of the complete() procedure. I included the original version since the program below tests both. I took the comments (which were useful by the way) out of the original since it was 40 lines even without them: procedure main() l := ["idaho","ohio","utah","indiana","illinois","texas","iowa"] write("\nProgrammer does the work:") every write("\t",complete("i",l)) write("\nIcon does the work:") every write("\t",terscomp("i",l)) end procedure terscomp(s,st) suspend match(s,p := !st) & p end procedure complete(s,st) local dfstn, c, l, old_char, newtbl, str, strset static t initial t := table() if /s & /st then { t := table() collect() fail } type(st) == ("list"|"set") | stop("error (complete): list or set expected for arg2") /t[st] := table() dfstn := t[st] every c := !s do { if /dfstn[st] then { l := sort(st) newtbl := table() old_chr := "" every str := !l do { str ?:= (chr := move(1), tab(0)) | next if old_chr ~==:= chr then strset := set() insert(newtbl, chr, insert(strset, str)) } insert(dfstn, st, newtbl) } st := \(\dfstn[st])[c] | fail } suspend s || !st end --- --- | S | Iconic Software, Inc. - Jerry Nowlin - uunet!isidev!nowlin --- ---