This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-25
Channels
- # aleph (2)
- # aws (2)
- # beginners (37)
- # boot (23)
- # cider (29)
- # clara (34)
- # cljs-dev (2)
- # cljsrn (17)
- # clojure (230)
- # clojure-dev (47)
- # clojure-italy (11)
- # clojure-nl (2)
- # clojure-poland (5)
- # clojure-russia (52)
- # clojure-sg (1)
- # clojure-spec (70)
- # clojure-uk (73)
- # clojurescript (31)
- # core-async (9)
- # cursive (15)
- # datomic (39)
- # events (1)
- # graphql (1)
- # lein-figwheel (2)
- # luminus (13)
- # off-topic (2)
- # onyx (29)
- # other-lisps (1)
- # parinfer (15)
- # pedestal (14)
- # re-frame (41)
- # reagent (24)
- # ring (4)
- # ring-swagger (12)
- # rum (1)
- # spacemacs (3)
- # specter (1)
- # test-check (13)
- # timbre (9)
- # unrepl (29)
- # vim (5)
@wparker thanks, will check it out. to have a real life value, FSMs need to support arbitrary code (i/o) execution as part (or as a consequence) of the state's transitions as well, so that comes down to a design decisions in both cases. In the exercise app I am (re)writing now - html5 video/audio tags are basically i/o, as far as the rest of the buttons in UI are concerned, despite those tags being their own FSMs.
@U051HUZLD I was thinking of mainly what types the rules could insert; given an arbitrary set of rules one can’t infer which other rules a given rule could trigger. It is possible to add metadata of some kind specifying this or to parse it if you restrict the RHS code you write to something you can reliably parse. This seemed possibly relevant if you were trying to translate rules to a FSM, specifically w.r.t. the allowed state transitions.
Having trouble wrapping my head around how to refer to the instance showing up in the LHS
(defprotocol IFoo
(test-foo [this]))
(defrule is-foo
[IFoo (test-foo ?not sure how to express?)]
=>...)
@ryanbrush Thanks for the help in advance 🙂
@iku000888 Ahh, I thought you meant calling protocol-based methods on the LHS. The type the rules matches needs to be an actual type, either a Java type or a Clojure type via deftype.
(The one exception is customized "types" discussed here, but this probably isn't applicable to your discussion: http://www.clara-rules.org/docs/fact_type_customization/)
Just thought at first glance I could reify a bunch of stuff and passing it through rules would be a usecase
(defprotocol IFoo
(test-foo [this]))
(deftype Foo []
IFoo
(test-foo [this] true))
(defrule is-foo
[Foo (test-foo ?not sure how to express?)]
=> (println "is a foo"))
Heads up about something potentially tricky: If you’re on the JVM when you create a protocol, behind the scenes Clojure creates a corresponding Java interface of the same name. An interface is a type that you can write rules against, but it might not do what you expect. Only types that Clojure knows satisfy the protocol at the time of their creation will implement the interface. For example:
` user=> (defprotocol MyProtocol (proto-method [_]))
MyProtocol
user=> (defrecord MyRecord1 [] MyProtocol (proto-method [_] "Hello World"))
user.MyRecord1
user=> (defrecord MyRecord2 [])
user.MyRecord2
user=> (extend-type MyRecord2 MyProtocol (proto-method [_] "Hi World"))
nil
user=> (proto-method (->MyRecord1))
"Hello World"
user=> (proto-method (->MyRecord2))
"Hi World"
user=> (instance? user.MyProtocol (->MyRecord1))
true
user=> (instance? user.MyProtocol (->MyRecord2))
false
`In another ns you could potentially import the interface rather than the protocol depending on how you set up your ns header i.e. import vs require on it
Yes, if Foo is a type, you should be able to invoke the test-foo protocol method on it like you show.
Just be aware you might have to reload your rules if you redefine the types in a REPL, since the type will change when you do that. 😉
@ryanbrush blogged about my first glance of clara-rules (for people in Japan) and thanked you there. Hope that is okay.
@iku000888 Nice! Thanks for blogging about our little project. 😉