tonsky / datascript

Immutable database and Datalog query engine for Clojure, ClojureScript and JS
Eclipse Public License 1.0
5.45k stars 304 forks source link

Allow calling `clojure.core` functions in queries #424

Open zoren opened 2 years ago

zoren commented 2 years ago

In Datomic:

(q
 '[:where
   [(ground {}) ?m]
   [(assoc ?m :x 5) ?m2]
   :find ?m2 .])

returns {:x 5}. But it fails in datascript with clojure.lang.ExceptionInfo: Unknown function 'assoc in [(assoc ?m :x 5) ?m2]

Should we allow all functions in clojure.core (except eval) in datascript as well?

tonsky commented 2 years ago

I think you can call any function by fully qualifying its name (in Clojure). We might also check clojure.core by default, I guess

zoren commented 2 years ago

I think you can call any function by fully qualifying its name (in Clojure). We might also check clojure.core by default, I guess

Ah thanks didn't know. If we did we wouldn't need to list them explicitly here: https://github.com/tonsky/datascript/blob/master/src/datascript/built_ins.cljc#L80

tonsky commented 2 years ago

Those are for ClojureScript, since it doesn’t have runtime resolve