Echo3

Now, let's try a variation; program Echo3 writes Hello!\n to stdout once a second. The user can change this message by typing a line on stdin; after the line is finished with a return, the line typed will be the new message. Here is the program:


module Echo3 where

import POSIX

echo3 env = class

   current := "Hello!\n"

   save str = action
      current := str

   tick = action
      env.stdout.write current
      after (sec 1) tick

   result action
      env.stdin.installR save
      tick
   
root = newRoot echo3


When running Echo3 one notices a peculiarity of the standard implementation of the POSIX environment: the screen doubles as both the output device stdout and as user feedback part of the input device stdin. Thus, output is intertwined with input characters in a rather unsatisfactory way.