Pdfsm:
Filter:
Classes | Streams-Patterns-Events > Patterns > List > Indexing

Pdfsm : ListPattern : Pattern : AbstractFunction : Object

deterministic finite state machine

Description

Pdfsm is a deterministic finite state machine with signal input (written by by ccos).

Class Methods

Pdfsm.new(list, startState: 0, repeats: 1)

Arguments:

list

a list consisting of the stream which gives input signals to determine state transitions, and then dictionary entries, one for each state, mapping the destination state and yield streams to those input signals.

startState

an integer index for the state to start with.

repeats

an integer giving the number of times the pattern should cycle. A cycle ends when the signal stream ends or nil is given for the destination state to a signal value, see below.

Inherited class methods

Instance Methods

Inherited instance methods

Undocumented instance methods

.embedInStream(inval)

.startState

.startState = value

Examples

list structure:
[
signal stream
can be a stream of anything which can serve as a key for an associative collection. integers, symbols, etc... asStream is called on this for each repeat.
states
states should be an instance of IdentityDictionary, Event or some other associative collection.

]
list syntax:
[
signal stream,
( // state 0,
signal value : [destination state, return stream or pattern],
signal value : [destination state, return stream or pattern]
),
... // state 1 ... N
]
Any number of states can be given, and are indexed by the order in which they are given.

If the fsm is in state x and it receives a signal value y it looks up y in the state dictionary supplied for x, if there is no y entry, it looks for a \default entry and uses that.

The next state is then set to destination state, and the stream yielded is given by return stream or pattern. That is unless the destination state is given as nil, or if a destination state is given for which you have not supplied a dictionary - in both cases the current cycle ends and any remaining repeats are executed. If there is no signal value given for a particular signal, and no \default is supplied then one will get a runtime error.