Live data from Hacker News

Show HN: State Trooper – Tiny, no frills state machine for Go

github.com

11–20 of 63 posts

Re: Show HN: State Trooper – Tiny, no frills state machine for Go

#18
A state machine (specifically a FSM) class is something I end up having to reinvent in every new language I've adopted. Such a useful pattern whose need comes up repeatedly. Especially in games/sims or in anything with a GUI. Since I've been making both for decades I have a lot of homegrown FSM classes sitting around. :-p

Re: Show HN: State Trooper – Tiny, no frills state machine for Go

#19

A state machine (specifically a FSM) class is something I end up having to reinvent in every new language I've adopted. Such a useful pattern whose need comes up repeatedly. Especially in games/sims or in anything with a GUI. Since I've been making both for decades I have a lot of homegrown FSM classes sitting around. :-p

I am working on a state machine formulation/notation that can be executed.

The runtime is multithreaded and parallel.

The idea is to execute the following state machine:

  thread(s) = fact(variable) | send(message) | receive(message2);
  thread(r) = fact(variable) | receive(message) | send(message2);
This program waits until thread(s) is true in another thread until thread(r) is true, everything left of the equals symbol needs to be true before it passes to the next group of facts after the = symbol. Then it waits for "fact(variable)" to be fired, then when all those atoms are true, the state transitions past the pipe symbol and does a send(message) while the other thread does a receive(message) and then the process is repeated in the opposite direction. I've not shown it here, but you can wait for multiple facts to be true too.

Here's a state machine for an (echo) server that is intended to be mapped to epoll or libiouring:

   accept | { submit_recv! | recv | submit_send } { submit_send! | send | submit_recv }
The curly brackets means parallel state machines that run independently, like a fork.

Re: Show HN: State Trooper – Tiny, no frills state machine for Go

#20
post #17

enums with associated values (like in swift) really are the thing i miss the most in go.

Yeah, yet another Algol 60 missing feature.

I really don't get how one can suggest the iota const dance with a straight face as an alternative.

Post reply on HN