Logiweb(TM)

7.15.7 Eecho

Prev Up Next Page 269 of 800 Search internet


The base page defines four Logiweb machines named hello, echo, eecho, and lgciotest. The hello machine prints 'Hello world' and exits. The echo machine echos input from the terminal back to the terminal except that it quits when it receives a 'q'. The eecho machine does the same except that it echos each character twice. The lgciotest machine exercises the lgcio interface.

In the following we define the eecho machine slightly differently from the way it is defined on the base page. States as lgs source, the eecho machine may be defined thus:

   define "execute" of "eecho" as << Eecho >> end define

The rendering of that looks thus:

define "execute" of "eecho" as << Eecho >> end define

The definition causes lgc(1) to generate a machine named eecho which has Eecho as boot handler. We may then define Eecho:

   eager define Eecho as map ( \ x . Eecho1 ( x ) ) end define

The rendering of that looks thus:

eager define Eecho as map ( \ x . Eecho1 ( x ) ) end define

So the real work is delegated to the Eecho1 function which we may define thus:

   eager define Eecho1 ( x ) as
   if x atom then
   << << << 0 ,, "read" >> >> ,,
      << << 0 ,, "exec" >> ,, true ,, Eecho >> >> else
   let e = x head in
   if .not. e head = << 0 ,, "read" >> then
      Eecho1 ( x tail ) else
   if e first != "q" then
   << << 0 ,, "write" >> ,, e first :: e first >> ::
      Eecho1 ( x tail ) else
   << << << 0 ,, "write" >> ,, 10 >> ,,
      << << 0 ,, "quit" >> ,, 0 >> >> end define

The Eecho1 function runs through the elements e of the list x of input messages. Eecho1 ignores input messages which are not read replies. In this way it ignores exec replies and the boot event.

If Eecho1 encounters a read reply which contains a 'q' then it writes code 10 (newline) to the terminal and quits. For read replies containing characters other than 'q', Eecho1 generates a write request which contains two copies of the input character.

If Eecho1 encounters the end of the list x of input messages, then it generates a read request and an exec request. The exec request comes last since all messages after the exec request will be ignored anyway. The exec event contains a dummy process and specifies Eecho as the handler to be used in the next run of the input-eval-output loop.

Prev Up Next Page 269 of 800 Search logiweb.eu

Copyright © 2010 Klaus Grue, GRD-2010-01-05