News for hackers. Stuff that matters.
Re:State Machines in Go by ericbb on Sunday February 10, 2013 @02:55PM (#5197569)
It's interesting to contrast this design with what Rob Pike presented in his talk on the Go template lexer. Some differences:

(1) Pike's is more static: there is no Machine struct and states are identified with handlers so that there is no table lookup in the loop.

(2) Pike chose to go with a modifiable lexer struct rather than threading a cargo value through the machine.

(3) Pike used nil for all end states.

The main design questions are probably:

(a) Do you need to construct machines at runtime?

(b) Do you need state names available at runtime?

Re:State Machines in Go by stevvooe on Sunday February 10, 2013 @04:34PM (#5198009)
For an example of a runtime state machine, you may want to take a look at Russ Cox's implementation of NFA simulation for regexp in go [1]. The concepts may be a little impenetrable for a Sunday, but there are some interesting references in the source.

[1] http://golang.org/src/pkg/regexp/exec.go