mriehl/fysom — pull request #11 by astanin (2014-07-07 17:28:31+00:00)
Title: Extend Fysom constructor to allow for terser FSM specifications

* Accept an alternative transition specification as a 3-tuple (name, src, dst)
* Optional named arguments (initial, events, callbacks, final) to override cfg dictionary
* Write a detailed docstring with an example on Fysom.__init__

Rationale:

* Specifying transition as 3-tuples is shorter than using dictionaries. Compare:

```
fsm = Fysom({ 'initial': 'green',
'events': [
{'name': 'warn', 'src': 'green', 'dst': 'yellow'},
{'name': 'panic', 'src': 'yellow', 'dst': 'red'},
{'name': 'calm', 'src': 'red', 'dst': 'yellow'},
{'name': 'clear', 'src': 'yellow', 'dst': 'green'} ] })
```

vs

```
fsm = Fysom({ 'initial': 'green',
'events': [('warn', 'green', 'yellow'),
('panic', 'yellow', 'red' ),
('calm', 'red', 'yellow'),
('clear', 'yellow', 'green')])
```

* Named arguments are more pythonic ("Flat is better than nested") and allow
to discard one level of curly braces and quotes around argument names.
Overall, the new syntax is easier to type on standard US keyboard.
Compare

```
fsm = Fysom({ 'initial': 'green',
'events': [('warn', 'green', 'yellow'),
('panic', 'yellow', 'red' ),
('calm', 'red', 'yellow'),
('clear', 'yellow', 'green')] })
```

vs

```
fsm = Fysom(initial='green',
events=[('warn', 'green', 'yellow'),
('panic', 'yellow', 'red' ),
('calm', 'red', 'yellow'),
('clear', 'yellow', 'green')])
```

* The change is backwards compatible with the old syntax. Named
arguments are optional and override (update) the configuration
dictionary if there is any.

* The detailed docstring on Fysom helps exploratory programming in
interactive environments.