Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!ucbvax!isidev.UUCP!nowlin From: nowlin@isidev.UUCP Newsgroups: comp.lang.icon Subject: Re: RE: terrible code Message-ID: <9103191156.AA24294@uunet.uu.net> Date: 19 Mar 91 11:56:08 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 52 In message <9103190300.AA10894@turing.cse.nau.edu> From: (Steve Wampler) > } Out of curiousity (and because I like bizarre code), couldn't > } the above be written: > } > } m := 0 > } while m >:= *(s[i:j] ? =!l) > } return i + (0 ~= m) > } > } instead? (No, I haven't tried it, but it seems the same to me...) > > Sigh. Make that a <:=, not >:=. Good reduction. The only problem with this is that if someone were to include an empty string in the list they're matching this solution would fail even if it matched the empty string. (I know...who cares!) A simple modification fixes that though. I added enough to test this. Look at an earlier posting to see comments: procedure main(args) s := "that begins this string" l := ["th","that beg","not close","","tha","begins t","that b","t"] write(longstr(l,s,6,12)) | write("nomatch") l := ["th","that beg","not close","tha","begins t","that b","t"] write(longstr(l,s,6,12)) | write("nomatch") end procedure longstr(l,s,i,j) ##### borrowed ##### /s := &subject if \i then { if i < 1 then i := *s + (i+1) } else i := \&pos | 1 if \j then { if j < 1 then j := *s + (j+1) } else j := *s+1 ##### borrowed ##### m := 0 while m <:= *(p := (s[i:j] ? =!l)) if /p then fail else return i + m end +-------------------------------------------------------------------------+ | --- --- | | | S | Iconic Software, Inc. - Jerry Nowlin - uunet!isidev!nowlin | | --- --- | +-------------------------------------------------------------------------+