Skip to content

Document namespaced clojure function requirement #488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jessie-ross
Copy link

@jessie-ross jessie-ross commented Jun 23, 2025

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:

@tonsky
Copy link
Owner

tonsky commented Jun 23, 2025

This is not exactly true. These functions don’t need to be qualified:

(def query-fns
{'= =, '== ==, 'not= not=, '!= not=,
'< less, '> greater, '<= less-equal, '>= greater-equal,
'+ +, '- -, '* *, '/ /,
'quot quot, 'rem rem, 'mod mod, 'inc inc, 'dec dec, 'max max, 'min min,
'zero? zero?, 'pos? pos?, 'neg? neg?, 'even? even?, 'odd? odd?, 'compare compare,
'rand rand, 'rand-int rand-int,
'true? true?, 'false? false?, 'nil? nil?, 'some? some?, 'not not, 'and and-fn, 'or or-fn,
'complement complement, 'identical? identical?,
'identity identity, 'keyword keyword, 'meta meta, 'name name, 'namespace namespace, 'type type,
'vector vector, 'list list, 'set set, 'hash-map hash-map, 'array-map array-map,
'count count, 'range range, 'not-empty not-empty, 'empty? empty?, 'contains? contains?,
'str str, 'subs, subs, 'get get,
'pr-str pr-str, 'print-str print-str, 'println-str println-str, 'prn-str prn-str,
're-find re-find, 're-matches re-matches, 're-seq re-seq, 're-pattern re-pattern,
'-differ? -differ?, 'get-else -get-else, 'get-some -get-some, 'missing? -missing?, 'ground identity,
'clojure.string/blank? str/blank?, 'clojure.string/includes? str/includes?,
'clojure.string/starts-with? str/starts-with?, 'clojure.string/ends-with? str/ends-with?
'tuple vector, 'untuple identity})

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:

Screenshot 2025-06-23 at 11 59 32

@jessie-ross
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants