Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site utflis.UUCP Path: utzoo!utcsri!utai!utflis!chai From: chai@utflis.UUCP (Henry Chai) Newsgroups: net.lang Subject: Re: Snobol -> Icon translation Message-ID: <543@utflis.UUCP> Date: Thu, 24-Oct-85 20:54:25 EDT Article-I.D.: utflis.543 Posted: Thu Oct 24 20:54:25 1985 Date-Received: Fri, 25-Oct-85 01:35:02 EDT References: <45000004@hpcnof.UUCP> Reply-To: chai@utflis.UUCP (Henry Chai) Organization: FLIS, University of Toronto Lines: 65 Summary: In article <45000004@hpcnof.UUCP> dat@hpcnof.UUCP writes: > > &ANCHOR = 1 > &TRIM = 1 >TOP OUTPUT = "WHAT IS YOUR NAME?" > STRING = INPUT > STRING "DAVE" RTAB(0) :F(OTHER) > OUTPUT = "HELLO DAVE!" :(END) >OTHER OUTPUT = "I DON'T KNOW YOU!" :(TOP) >END > # Here is a translation into a one-liner Icon program procedure main() while ( write("What is your name?") , String := trim(read()) , not( if String[1:0] == "DAVE" then write("Hello Dave!")) ) do write("I don't know you!") end # but it's very bad style. # # Explanation: # while (x1, x2, x3) is just the same as while (x1 & x2 & x3). # The reason why this can be done here is that all expressions either # suceed or fail. Thus the while will stop only on the third part # (i.e. when the string "DAVE" is matched with the complete line) # Since the write and read statements will always suceed. # String[1:0] will take the place of &ANCHOR and RTAB(0) i.e. from the # first char to the last (if I've remembered my SNOBOL correctly!) # ("string" is a reserved word) # # For clarity, you can have # procedure main() while /done do { write("What is your name?") String := trim(read()) if String[1:0] == "DAVE" then { write("Hello Dave!") done := 0 # or any value } else write("I don't know you") } end # # Explanation: # The operation "/done" tests whether "done" is a null variable # (i.e. whether it's defined or not). Once you assigned a value # to "done", "/done" fails. ---------------------------------------------------------------------------- In general Icon is syntactically similar to Pascal, but the structure is like C (i.e. no nested blocks). I trust you have the book "The Icon Programming Language" by Griswold & Griswold ?? (Prentice Hall, 1983) -- Henry Chai, just a humble student at the Faculty of Library and Information Science, U of Toronto {watmath,ihnp4,allegra}!utzoo!utflis!chai