How to make a condition on string length?

This doesn’t work and I don’t understand why:

#+BEGIN_QUERY
{:query [
        :find ?p ?ns2 ?ns1 ?name
        :keys a b c d
        :where
        [?p :block/namespace ?ns2]
        [?ns2 :block/namespace ?n1]
        [?ns1 :block/name ?name]
        [(.length ?name) ?len]
        [(= ?len 1)]
 ]
 :view (fn [r] [:pre.code (pprint r)])
}
#+END_QUERY
Unknown function '.length in [(.length ?name) ?len]

Where did you find .length ?

Dunno, somewhere in the internet. I also tried (strlen ...), it didn’t work as well. This is all more a guess.

What should I consult with? Is there a documentation? I don’t really want to create help threads every time I need to find a library function.

  • Guesses rarely ever work.
    • Asking why a guess (whether from human or from LLM) doesn’t work, won’t attract much help.
    • In clojurescript, length is typically expressed as count .
  • Given that documentation is lacking, should search for functions in the forum.
    • If you don’t find what you need, it is fair to ask.
    • To see what is available for string manipulation, search for clojure.string/
      • Some functions are available.
      • Many others are currently not.
1 Like

Guesses rarely ever work.

For sure. Well, I found where I looked it up:

https://datomic.narkive.com/Z12BoypM/string-length-function-causes-eof-while-reading-exception

In clojurescript, length is typically expressed as count .

Oh, yeah, I forgot that I started with it. It didn’t work. But now I realize I was using it in a wrong way: I didn’t assign its value on a separate line before. Now it seems to be fixed:

#+BEGIN_QUERY
{:query [
        :find ?p ?ns2 ?ns1 ?name
        :keys a b c d
        :where
        [?p :block/namespace ?ns2]
        [?ns2 :block/namespace ?n1]
        [?ns1 :block/name ?name]
        [(count ?name) ?len]
        [(= ?len 1)]
 ]
 :view (fn [r] [:pre.code (pprint r)])
}
#+END_QUERY

Thanks!

To see what is available for string manipulation, search for clojure.string/

Thanks, it gives many results. Tho, it’s not a documentation :slight_smile:

Logseq implements datascript, can find functions here:

'clojure.string/blank? str/blank?, 'clojure.string/includes? str/includes?,
'clojure.string/starts-with? str/starts-with?, 'clojure.string/ends-with? str/ends-with?

For this only the full clojure.string/ works in :where, not the str/. The str/ works in :result-transform and :view.

2 Likes