Document namespaced clojure function requirement
I haven't used Datomic, but I have been following it's documentation to learn Datascript, I believe have found this gap in the behaviour between Datomic and Datascript queries, it would be good to document it:
- https://github.com/tonsky/datascript/issues/424
This is not exactly true. These functions don’t need to be qualified: https://github.com/tonsky/datascript/blob/8c01d1b7e401ab1765f2933164267922f550d753/src/datascript/built_ins.cljc#L81-L99
For custom functions, in CLJS even fully-qualified won’t work. You’ll have to pass fn as an argument.
Finally, Datomic seems to require fully-qualified too:
Finally, Datomic seems to require fully-qualified too:
Ah I wasn't clear enough perhaps, I mean clojure.core functions, see this example:
(require '[datomic.api :as d :refer [q db]])
(def uri "datomic:dev://localhost:4334/mbrainz-1968-1973")
(def conn (d/connect uri))
(def the-db (d/db conn))
;; Check I am running this correctly:
(d/q '[:find ?artist-name .
:in $
:where
[?a :artist/name ?artist-name]
[?t :track/artists ?a]
[?t :track/name "Baby's Heartbeat"]]
the-db) ;; => "John Lennon"
;; clojure.core/concat is included
(d/q '[:find ?result .
:in $ ?a ?b
:where
[(concat ?a ?b) ?result]]
the-db ["a"] ["b"]) ;; => ("a" "b")
;; Checking if it includes symbols present in the current namespace
(defn foo [a] (str a "-foo"))
;; It doesn't
(d/q '[:find ?result .
:in $ ?a
:where
[(foo ?a) ?result]]
the-db "a") ;; => Unable to resolve foo in this context
(d/q '[:find ?result .
:in $ ?a
:where
[(user/foo ?a) ?result]]
the-db "a") ;; => "a-foo"
I was following this blog post and tripped over the difference between datomic and datascript on functions like concat, and butlast. I am not sure whether just Datomic has a larger amount of functions allowed or whether it includes clojure.core.
Now that I've solved the issue it isn't of great importance to me, but I was thinking it might be nice to document it.
Happened across some further official docs in the Datomic Query Reference:
Datomic provides the following built-in expression functions and predicates:
- [...]
- All of the functions from the clojure.core namespace of Clojure, except eval.
- [...]
https://docs.datomic.com/query/query-data-reference-only.html#built-in-functions
Function names outside clojure.core need to be fully qualified and included on the classpath for Pro, or in the ion :allow list for Cloud.
https://docs.datomic.com/query/query-data-reference-only.html#calling-clojure-functions
Do you want to update the PR?