7 ms·
Once upon a time I have implemented POP3 server protocol state machine in Clojure. 180 lines in total, of which 40 were FSM declaration, 140 command handling f
by juskrey 7y ago
Once upon a time I have implemented POP3 server protocol state machine in Clojure.
180 lines in total, of which 40 were FSM declaration, 140 command handling functions.
Not sure I'll ever want to approach FSM in any other language, unless no other choice.
- harperlee 7y agoCan you perhaps point to it? Sounds interesting to read that code!
- juskrey 7y agoYes. Can't share the whole repo (it's our internal product), but here are two files (FSM macro and FSM itself) you can explore. Let me know it that helps. https://gist.github.com/juskrey/61148c98bdde871a8d3743f54b822ae5 https://gist.github.com/juskrey/61148c98bdde871a8d3743f54b82... https://gist.github.com/juskrey/127cf8456fc527d20ed5e244ce01e312 https://gist.github.com/juskrey/127cf8456fc527d20ed5e244ce01...
- diggan 7y agoInteresting, thanks a lot for being able to share those examples! I think you managed to find a bug in the GitHub syntax highlighter, as https://gist.github.com/juskrey/61148c98bdde871a8d3743f54b822ae5 https://gist.github.com/juskrey/61148c98bdde871a8d3743f54b82... has no colors after line ~108.
- diggan 7y agoNot OP but there is tons of FSM implementations/libs in Clojure scattered around GitHub and GitLab if you search for them. Some of them: - https://github.com/ztellman/automat https://github.com/ztellman/automat - https://github.com/metosin/tilakone https://github.com/metosin/tilakone - https://github.com/cdorrat/reduce-fsm https://github.com/cdorrat/reduce-fsm
- Dowwie 7y agoDid you iterate to a FSM solution, from many nested conditions, or use it right from the start? I'm fighting the urge to write any FSM without having the absolute certainty that it is needed. There seems no other way than by refactoring to an FSM.
- deleted 7y ago[deleted]
- juskrey 7y agoI have started from already existing FSM libs (which did not fit well) and after couple of experiments understood that creating own custom FSM processor is a no-brainer with clojure/core.match