Updated 2012-08-13 17:06:13 by aspect

State machines can be a powerful way to sequence execution. This is a link to a package to implement Moore type state machines in Tcl.

http://chiselapp.com/user/mangoa01/repository/mrtools/doc/tip/moore/wiki/intro.wiki

It is rather more complete than the simpler examples on the wiki, of course, at the expense of a bit more learning curve. It is large enough that it is hard to deal with as a wiki page, so I have put it in Fossil repository that I have been building for some of these types of tools.

For those that prefer the Mealy formulation, that can be found at Mealy Type State Models.

The difference between the two models is that a Moore Machine's output is determined solely by its current state, while a Mealy machine's output is determined by its current state and its current (most recent) input. Perhaps more intuitively, a Moore Machine has an output symbol associated with (attached to) each state, while a Mealy Machine has one attached to each transition (or edge between states). The two formulations are equivalent in power - every Moore Machine can be translated into an equivalent Mealy Machine, and vice versa - the difference is a matter of convenience of representation and implementation.

jhjl Using Tcl8.6 on Windows 7 I get an error loading the package. I tried a teacup update but problem persists.
package require moore 1.9
unknown data type, "dict"
    while executing
"relvar create StateMachine {
        MachineId       string
        ModelName       string
        CurrState       string
        Options         dict..."
    (in namespace eval "::moore" script line 35)
    invoked from within
"namespace eval ::moore {
    variable revision 1.9

    namespace export model
    namespace export generate
    namespace export delay
    namespace ..."
    (file "C:/Tcl/lib/teapot/package/tcl/teapot/tcl8/8.5/moore-1.9.tm" line 93)
    invoked from within
"source -encoding utf-8 C:/Tcl/lib/teapot/package/tcl/teapot/tcl8/8.5/moore-1.9.tm"
    ("package ifneeded moore 1.9" script)
    invoked from within
"package require moore"
    ("uplevel" body line 1)
    invoked from within
"uplevel #0 {package require moore}"
    invoked from within
"interp eval $::tkcon::OPT(exec) $args"
    (procedure "::tkcon::EvalSlave" line 2)
    invoked from within
"EvalAttached $cmd"

gam, 17 July 2012

I suspect that you have a version of TclRAL that is built against Tcl 8.4 (before dictionaries were a built in type). You might want to get the TclRAL package from sourceforge [1]. That one was built against Tcl 8.5. If you obtained TclRAL from the ActiveState teapot it could have been built against Tcl 8.4 (just a guess here).

jhjl You guessed right! The ActiveState teapot contains TclRAL 0.10.2 built against Tcl8.4. I downloaded the binary from SourceForge and this version is linked against 8.6. The SourceForge version loads without complaint.
C:\Tcl\bin>teacup remove ral
 Removing instance package ral 0.10.2 win32-ix86

C:\Tcl\bin>teacup install ral
Resolving ral ... [package ral 0.10.2 win32-ix86 @ http://teapot.activestate.com]
Resolving Tcl 8.4 -is package ... [package Tcl 8.6 _ ... Installed outside repository, probing dependencies]

Retrieving package ral 0.10.2 win32-ix86 ...@ http://teapot.activestate.com ... Ok

Installing into C:/Tcl/lib/teapot

Installing package ral 0.10.2 win32-ix86

Having done the install above the ActiveState teacup.txt file contains a Meta require {Tcl 8.4} whereas the SourceForge version contains a Meta require {Tcl 8.5}