datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
rnagpal 2018-05-01T15:02:08.000027Z

I am using a custom clojure predicate function

rnagpal 2018-05-01T15:02:12.000733Z

in query

rnagpal 2018-05-01T15:02:21.000397Z

and my code is in a cljc file

rnagpal 2018-05-01T15:02:33.000180Z

when included on clj, it works fine

rnagpal 2018-05-01T15:02:55.000017Z

when included in cljs side it complains Unknown function

rnagpal 2018-05-01T15:03:13.000695Z

I have given the full namespace/fn-name

rnagpal 2018-05-01T15:11:59.000393Z

I see a test in test/datascript/test/query_fns.cljc in code

rnagpal 2018-05-01T15:12:18.000641Z

(defn sample-query-fn [] 42)

#?(:clj
(deftest test-symbol-resolution
  (is (= 42 (d/q '[:find ?x .
                   :where [(datascript.test.query-fns/sample-query-fn) ?x]])))))

rnagpal 2018-05-01T15:12:31.000405Z

Not sure why just a clj version is defined ? and not for cljs ?

rnagpal 2018-05-01T15:17:02.000098Z

aah in the src/datascript/query.cljc I see

(defn- resolve-sym [sym]
  #?(:cljs nil
     :clj (when (namespace sym)
            (when-let [v (resolve sym)] @v))))
So no resolutions for cljs

rnagpal 2018-05-01T15:22:57.000429Z

Just passed the function as variable and then it worked 🙂 Just like the way its done here

(testing "Returning nil from function filters out tuple from result"
      (is (= (d/q '[:find ?x
                    :in    [?in ...] ?f
                    :where [(?f ?in) ?x]]
                [1 2 3 4]
                #(when (even? %) %))
           #{[2] [4]})))