Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!mis.mcw.edu!tenaglia From: tenaglia@mis.mcw.edu (Chris Tenaglia - 257-8765) Newsgroups: comp.lang.icon Subject: Prompting String Input Procedure Message-ID: <8911301956.AA28554@uwm.edu> Date: 30 Nov 89 17:49:57 GMT Sender: daemon@ucbvax.BERKELEY.EDU Distribution: inet Organization: The Internet Lines: 52 Dear Icon-Group : Here is a simple and handy procedure I use all over the place. It's called input. I've used it in DOS, VMS, and UNIX. Although in unix I've had to make it a little different in some cases. Problem : Getting a screen inputted value takes 2 lines. writes("Enter Value>") value := read() Solution: It would be nice to do it in one line. value := input("Enter Value>") Method : Input Procedure... procedure input(prompt) writes(prompt) return read() end Example : Main procedure parameters. This example also makes nice use of what I call the 'either or' construct (alternation). procedure main(files) source := (files[1] | input("Source File:") | stop("Cancelled")) target := (files[2] | input("Target File:") | stop("Cancelled")) VMS : The procedure will fail if CTRL_Z is pressed. This adds a little & of the failure driven stuff. DOS UNIX : However, under unix, CTRL_Z stops the process. And pressing CTRL_D seems to cause a failure avalanch. In one application I ended up defining . as the failure string. The procedure looks like ... procedure input(prompt) local temp writes(prompt) temp := read() if temp ~== "." then return temp else fail end Conclusion : I hope some of you out there may find this helpful/useful. Perhaps there is room for improvement, especially in the UNIX example. Perhaps instead of a single string, it can truly dynamic (like write()). Enjoy ! Chris Tenaglia (System Manager) Medical College of Wisconsin 8701 W. Watertown Plank Rd. Milwaukee, WI 53226 (414)257-8765 tenaglia@mis.mcw.edu