noprompt / meander

Tools for transparent data transformation
MIT License
922 stars 55 forks source link

Interpreter return IllegalArgumentException rather than nil. #164

Closed ribelo closed 3 years ago

ribelo commented 3 years ago

If the argument of the function returned by the interpreter is vector, it throws an exception if the query is unsolved.

(let [f (mi/finder
         ['?x '?y] "a")]
  (f {:a 1}))
;; => nil

(let [f (mi/finder
         ['?x '?y] "a")]
  (f [:a 1]))
;; => error: java.lang.ClassCastException: class java.lang.String cannot be cast
;; to class clojure.lang.IFn (java.lang.String is in module java.base of loader
;; 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')
jimmyhmiller commented 3 years ago

The second argument to mi/finder is supposed to be a function that will be passed the bindings (in this case it is the string "a"). The interpreter is trying to call that string as if it is a function.

If you wanted to use a pattern on the rhs try mi/rewriter instead.

(We might want to consider catching this instead of throwing the error deep down like this)

noprompt commented 3 years ago

Should we throw in some asserts for the arguments?

noprompt commented 3 years ago

Closing pending a patch or plan of action.