This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-17
Channels
- # announcements (3)
- # beginners (107)
- # calva (13)
- # clj-kondo (5)
- # cljsrn (21)
- # clojure (99)
- # clojure-australia (8)
- # clojure-dev (51)
- # clojure-europe (108)
- # clojure-nl (1)
- # clojure-portugal (3)
- # clojure-spec (9)
- # clojure-uk (10)
- # clojurescript (147)
- # component (7)
- # conjure (5)
- # core-async (2)
- # cursive (11)
- # datomic (11)
- # emacs (14)
- # graalvm (163)
- # graalvm-mobile (317)
- # honeysql (15)
- # introduce-yourself (4)
- # jobs (3)
- # lambdaisland (1)
- # lsp (19)
- # luminus (3)
- # malli (17)
- # off-topic (10)
- # pathom (11)
- # reagent (10)
- # remote-jobs (2)
- # ring (1)
- # shadow-cljs (22)
- # test-check (2)
- # testing (5)
- # tools-deps (39)
Anyone doing something like that for "dynamic" rules?
(defmacro eval-rules [form]
(walk/prewalk
(fn [e]
(if (and (seq? e) (= `unquote (first e)))
(eval (second e))
e))
form))
(eval-rules
'[[(reverse-edge ?from-concept ?type ?to-concept ?relation)
[(ground ~(set/map-invert some-config-map))
[[?type ?reverse-type]]]
[?relation :relation/concept-2 ?from-concept]
[?relation :relation/type ?reverse-type]
[?relation :relation/concept-1 ?to-concept]]])
I'm trying to create rules configured from some code...(let [some-config-map {:bar :foo :baz :bin}]
[['(reverse-edge ?from-concept ?type ?to-concept ?relation)
[(list 'ground (clojure.set/map-invert some-config-map))
'[[?type ?reverse-type]]]
'[?relation :relation/concept-2 ?from-concept]
'[?relation :relation/type ?reverse-type]
'[?relation :relation/concept-1 ?to-concept]]])
For more inspiration See the https://github.com/Datomic/mbrainz-sample/blob/master/src/clj/datomic/samples/mbrainz/rules.clj .If you come up with something you REALLY like @U47G49KHQ I'd be interested in seeing it.
Well, I've been thinking about it for a couple is hours, and so far eval-rules is the best thing I have...
Other things I considered is what you suggested, macro that does the same thing as eval-rules, but that was much more cumbersome than fn version, and syntax quoting with a lot of ~'?type
-like symbols