chai@utflis.UUCP (Henry Chai) (10/25/85)
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