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......and I don't want to pass this config map in addition to rules to queries since it's static. Any advice how to do that?
(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 .yeah “just quote the quoted bits” seems most straightforward to me
That's a lot of quoting...
If you come up with something you REALLY like @vlaaad 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
Ah, I also tried #=, but I couldn't reference the config-map with it, it was interpreted as symbol
Ha, first rule of #=
club, don't talk about #=
club 😉
This #= club membership didn't bear any fruits so far...