next up previous contents
Next: Tokens, bubbles, and metaparsing Up: User Interfaces and Metalanguage Previous: User interfaces   Contents


Using the loop

We illustrate the basic ideas of using the loop with a sample session with the interface for the vending machine. Once the VENDING-MACHINE-INTERFACE module has been entered, we must first initialize the loop by setting its initial state by means of the loop command.

  Maude> loop init .

We can inspect the state of the loop with the continue command, abbreviated cont, as follows:

  Maude> cont .
  result System: [nil, < idle ; null ; nil >, nil]

Once the loop has been initialized, we can input any data by writing it after the prompt enclosed in parentheses. For example,

  Maude> ($)

  Maude> (showCredit)
  credit: $

  Maude> ($)

  Maude> cont .
  result System: [nil, < idle ; $ $ ; nil >, nil]

  Maude> (q)

  Maude> (buy1Apple)

  Maude> (showBasket)
  basket: a

  Maude> (showCredit)
  credit: $ q q

  Maude> ($)

  Maude> (buy a : 3)

  Maude> (showBasket)
  basket: a a a a

  Maude> (showCredit)
  credit: q

  Maude> cont .
  result System: 
    [nil,
     < idle ; q a a a a ; nil >,
     '\u 'credit: '\o '\r '\! 'q '\o '\n]

Note that, as already mentioned, the data in the output stream remains there after being printed; it is removed at the time of the next input event.


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