home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / modula3 / 1105 < prev    next >
Encoding:
Internet Message Format  |  1993-01-12  |  2.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!asuvax!ncar!vexcel!copper!slate!lpratt
  2. From: lpratt@slate.mines.colorado.edu (Lorien Pratt)
  3. Newsgroups: comp.lang.modula3
  4. Subject: Trouble with stdin on RS/6000
  5. Message-ID: <1993Jan12.172641.40124@slate.mines.colorado.edu>
  6. Date: 12 Jan 93 17:26:41 GMT
  7. Sender: lpratt@slate.mines.colorado.edu (Lorien Pratt)
  8. Organization: Colorado School of Mines
  9. Lines: 70
  10.  
  11. Hi,
  12.   I'm trying to write a simple modula-3 program that takes input from the
  13. terminal.  Unfortunately, the program doesn't pause to wait for input from
  14. stdin; instead it receives an end of file indication.  If I echo the input
  15. to the program, however, it does work.  
  16.   Specifically, I've typed in Example 1-8 in Harbison (page 12).  It looks
  17. like this:
  18. ----
  19. MODULE WriteSum EXPORTS Main;
  20. IMPORT Wr, Rd, Fmt, Scan, Stdio;
  21.  
  22. PROCEDURE Read(): INTEGER =
  23.   BEGIN
  24.     RETURN Scan.Int( Rd.GetLine(Stdio.stdin));
  25.   END Read;
  26.  
  27. PROCEDURE Write(t:TEXT) =
  28.   BEGIN
  29.     Wr.PutText(Stdio.stdout, t);
  30.   END Write;
  31.  
  32. VAR n1, n2: INTEGER;
  33. BEGIN
  34.   Write("Please type two numbers on separate lines:\n");
  35.   n1 := Read();
  36.   n2 := Read();
  37.   Write("The sum of " & Fmt.Int(n1) & " And " & Fmt.Int(n2) & " is " &
  38. Fmt.Int (M^n1 + n2) & ".\n");
  39. END WriteSum.
  40.  
  41. -----
  42. Now, if I compile this and try to run it, I get the following error
  43. message:
  44. ----
  45. a.out
  46. ****************** EXCEPTION HANDLER STACK *********************
  47. 0x2ff7fa98 TRY-FINALLY  proc = 0x2006daac   frame = 0x2ff7fa8c
  48. 0x2ff7fb4c RAISES {}
  49. ****************************************************************
  50.  
  51.  
  52. ***
  53. *** runtime error:
  54. ***    Exception "Rd.EndOfFile" not in RAISES list
  55. ***
  56.  
  57. Please type two numbers on separate lines:
  58. Quit(coredump)
  59. ----
  60. But if I echo the proper input to the program, it works:
  61. ----
  62. echo "1
  63. 2" |a.out
  64. Please type two numbers on separate lines:
  65. The sum of 1 And 2 is 3.
  66. ----
  67.  
  68. I'd appreciate any pointers for how tell modula-3 to generate code to
  69. expect stdin from the terminal.  Thanks!
  70.  
  71.   --Lori
  72.  
  73.  
  74.  
  75.  
  76. -- 
  77. L. Y. Pratt                           Dept. of Math and Computer Science
  78. lpratt@franklinite.mines.colorado.edu Colorado School of Mines    
  79. (303) 273-3878 (work)                 402 Stratton                
  80. (303) 278-4552 (home)                 Golden, CO 80401, USA      
  81.