Why would the below fail with Execution error (IllegalArgumentException) at meander.interpreter.epsilon/match-clause-factory$fn$fn$fn (epsilon.cljc:490). Key must be integer
:
(let [q ['?y '?x]
f (mi/searcher
q ['?x])]
(f [:x 1]))
(defn project
"Helper which extracts the values of vars (keys) out a map in the
order they are given.
Example:
(let [f (mi/finder '[?x ?y] (project '[?y ?x ?y]))]
(f [1 2]))
;; => [2 1 2]"
[vars]
(fn [bindings] (mapv bindings vars)))
(let [q '[?y ?x]
f (mi/searcher
q (project ['?x]))]
(f [:x 1]))
;; => [1]
(defn debug
[vars]
(fn [bindings]
{:vars vars
:bindings bindings}))
(let [q '[?y ?x]
f (mi/finder
q (debug '?x))]
(f [:x 1]))
;; =>
;; {:vars ?x,
;; :bindings {:meander.interpreter.epsilon/cata #function
;; [meander.interpreter.epsilon/match-system-factory/fn--23289/f--23292] ,
;; ?y :x,
;; ?x 1}}
I suspect that if the data being thrown into the function returned by the intrepreter is a vector, it unfolds to something similar
(let [date [:x 1])
l ['?y '?x]
r '?x]
(let [idx (.indexOf l r)]
(.get data idx)))
I guess this is a bug, because if idx is nil
, the rest of the function should not be continued.
If you want to do something a bit more complicated then you should create a function that takes a query and that returns a function that takes a hasmap with the bindings.
(let [q '[?y ?x]
f (mi/finder
q {:a '?x})]
(f [:x 1]))
;; => nil
(let [q '[?y ?x]
f (mi/finder
q ((fn [x] (fn [bindings] {:a (get bindings x)})) '?x))]
(f [:x 1]))
;; => {:a 1}
Although IMHO does not make sense, it is better to build the collection that we need after obtaining the value
(let [q '[?y ?x]
f (mi/finder
q '?x)]
{:a (f [:x 1])})
Will take a look at this later today is someone else doesn't get to it first.
Sorry, I was busier than expected.
Yeah, the interpreter stuff likely has rough edges. Please also report these on Github too if you donβt mind. π