Code Monkey home page Code Monkey logo

Comments (4)

martinklepsch avatar martinklepsch commented on August 25, 2024

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.

martinklepsch avatar martinklepsch commented on August 25, 2024

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.

martinklepsch avatar martinklepsch commented on August 25, 2024

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.

osfameron avatar osfameron commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.