juji-io / datalevin

A simple, fast and versatile Datalog database
https://github.com/juji-io/datalevin
Eclipse Public License 1.0
1.13k stars 63 forks source link

Are rules with required bindings supported somehow? #205

Closed kipz closed 1 year ago

kipz commented 1 year ago

I'm trying to create a Rule that forces some vars to be bound. In this case, ?name:

  (d/q '[:find ?greeting
         :in $ %
         :where
         (say-hello "kipz" ?greeting)]
       db
       '[[(say-hello [?name] ?result)
          [(ground "hello, ") ?greeting]
          [(str ?greeting ?name) ?result]]])

But this unexpectedly fails warning of unbound vars:

; Execution error (ExceptionInfo) at datalevin.query/check-bound (query.cljc:751).
; Insufficient bindings: #{?name__auto__9} not bound in [(str ?greeting__auto__9 ?name__auto__9) ?greeting]

Without the [..bound vars..] notation, all works just fine:

(d/q '[:find ?greeting
         :in $ %
         :where
         (say-hello "kipz" ?greeting)]
       db
       '[[(say-hello ?name ?result)
          [(ground "hello, ") ?greeting]
         [(str ?greeting ?name) ?result]]])

->>

#{["hello, kipz"]}
huahaiy commented 1 year ago

Have you tried this in datascript?

kipz commented 1 year ago

Have you tried this in datascript?

Tried just now, and same result in datascript.

kipz commented 1 year ago

Just found this: https://github.com/tonsky/datascript/issues/441

Sorry, I didn't realisze that Datascript provided the Datalog parser/engine.