Comments (4)
Hey @timvisher, just stumbled upon this while looking for a solution myself. I came up with the following:
(defn possible-transitions [compiled-fsm state]
(let [alphabet (f/alphabet (:fsm (meta compiled-fsm)))]
(set (filter (fn [t] (a/advance compiled-fsm state t nil)) alphabet))))
This obviously isn't ideal computation-wise but I haven't been able to find the right knobs inside the library to give me the same result. For my use case it's ok.
@ztellman If there's a way to achieve this without brute-force as above an addition to the Readme would be a great :)
from automat.
I just noticed that the above snippet does trigger actions
which makes it potentially un-pure making it more or less useless. Anybody came up with a better approach in the meantime that is side-effect free?
from automat.
My new approach looks like this:
(defn dry-run-wrap
"Wrap `action-fn` so that it only calls `action-fn` if the FSM's state
does not contain a truthy value under `::dry-run`."
[action-fn]
(fn [state input]
(if (::dry-run state)
state
(action-fn state input))))
(defn possible-transitions [compiled-fsm state]
(let [alphabet (f/alphabet (:fsm (meta compiled-fsm)))
dry-run (assoc state ::dry-run true)]
;; SIGNAL using [t] here means we assume the FSMs signal function is `first`
(set (filter (fn [t] (a/advance compiled-fsm dry-run [t] false)) alphabet))))
I'm using dry-run-wrap
to wrap action functions so that they are effectively no-ops if the ::dry-run
key contains a truthy value.
from automat.
Agree that a way to check what the output states are would be a useful addition to the library, for various introspection abilities and tweaks. (Presumably the viz view
function uses some kind of similar hook, but I don't understand the code base well enough to see quite how.)
from automat.
Related Issues (20)
- different reducers for self-transitions HOT 2
- Compilation error in Clojure 1.8? HOT 2
- infinite loop with "or" HOT 3
- Wrong fsm/complement HOT 7
- Please consider doing a release. HOT 2
- [feature request] signal function return several values HOT 1
- Customize viz (edge) labels HOT 2
- Non-numeric input when numeric input is expected causes error, not rejection
- Link in the README to the docs is broken HOT 1
- Question, how do I view? HOT 2
- README example code errata HOT 1
- `greedy-find` not setting `:checkpoint` HOT 2
- Support character ranges
- Automaton with `a/not` triggers handlers unexpectedly
- WARNING: cljs.core/bit-or HOT 1
- Referencing a non-existent reducer should cause an error
- Nested a/* operators generate wrong fsm
- java -jar standalone.jar throws ExceptionInInitializerError - Caused by: j.l.ClassCastException: c.l.Var$Unbound cannot be cast to clojure.lang.MultiFn HOT 6
- Using AOT with clojurescript dependency throws ClassCastException HOT 5
- Automat "slow" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from automat.