next up previous contents
Next: User interfaces Up: User Interfaces and Metalanguage Previous: User Interfaces and Metalanguage   Contents


The LOOP-MODE module

Using object-oriented concepts, we specify in Maude a general input/output facility provided by the LOOP-MODE module shown below, which extends the module QID-LIST (see Section 7.10), into a generic read-eval-print loop.

  mod LOOP-MODE is
    protecting QID-LIST .
    sorts State System .
    op [_,_,_] : QidList State QidList -> System 
         [ctor special (...)] .
  endm

The operator [_,_,_] can be seen as an object--that we call the loop object--with an input stream (the first argument), an output stream (the third argument), and a state (given by its second argument). This read-eval-print loop provided by LOOP-MODE is a simple mechanism that may not be maintained in future versions, because the support for communication with external objects (see Section 8.4) makes it possible to develop more general and flexible solutions for dealing with input/output in future releases.

Since in the current release only one input stream is supported (the current terminal), the way to distinguish the input passed to the loop object from the input passed to the Maude system--either modules or commands--is by enclosing them in parentheses. When something enclosed in parentheses is written after the Maude prompt, it is converted into a list of quoted identifiers. This is done by the system by first breaking the input stream into a sequence of Maude identifiers (see Section 3.1) and then converting each of these identifiers into a quoted identifier by putting a quote in front of it, and appending the results into a list of quoted identifiers, which is then placed in the first slot of the loop object. The output is handled in the reverse way, that is, the list of quoted identifiers placed in the third slot of the loop object is displayed on the terminal after applying the inverse process of ``unquoting'' each of the identifiers in the list. However, the output stream is not cleared at the time when the output is printed; it is instead cleared when the next input is entered. We can think of the input and output events as implicit rewrites that transfer--in a slightly modified, quoted or unquoted form--the input and output data between two objects, namely the loop object and the ``user'' or ``terminal'' object.

Besides having input and output streams, terms of sort System give us the possibility of maintaining a state in their second component. This state has been declared in a completely generic way. In fact, the sort State in LOOP-MODE does not have any constructors. This gives complete flexibility for defining the terms we want to have for representing the state of the loop in each particular application. In this way, we can use this input/output facility not only for building user interfaces for applications written in Maude, but also for uses of Maude as a metalanguage, where the object language being implemented may be completely different from Maude. For each such tool or language the nature of the state of the system may be completely different. We can tailor the State sort to any such application by importing LOOP-MODE in a module in which we define the state structure and the rewrite rules for changing the state and interacting with the loop.


next up previous contents
Next: User interfaces Up: User Interfaces and Metalanguage Previous: User Interfaces and Metalanguage   Contents
The Maude Team