Skip to content

Function Input not Evaluated in Query Rules #311

Open

Description

@MyriaCore

I could easily be missing something, but to my current understanding, the intended behavior between the two code snippets below should be identical.

(d/q '[:find ?int
       :in ?intersection
       :where [(?intersection #{:a :b :c} #{:c :d :e}) ?int]]
     clojure.set/intersection))
;; => #{[#{:c}]}

(d/q '[:find ?int
       :in % ?intersection
       :where (intersection-rule #{:a :b :c} #{:c :d :e} ?int)]
  '[[(intersection-rule ?s ?t ?int)
     [(?intersection ?s ?t) ?int]]]
  clojure.set/intersection))
;; => Execution error (ExceptionInfo) at datascript.query/bind-by-fn (query.cljc:546). 
;;    Unknown function '?intersection__auto__1 in [(?intersection__auto__1 #{:c :b :a} #{:e :c :d}) 

Activity

  1. changed the title [-]Function input not evaluated in rules[/-] [+]Function Input not Evaluated in Query Rules[/+] on Aug 5, 2019
  2. tonsky commented on Aug 6, 2019

    @tonsky
    Owner

    Yes, seems like a bug here

    (walk/postwalk
    #(if (free-var? %)
    (db/some-of
    (replacements %)
    (symbol (str (name %) "__auto__" seqid)))
    %)
    clauses))))

    It tries to rename rule vars based on if symbol starts with a ?, not on actual arguments list

  3. MyriaCore commented on Aug 6, 2019

    @MyriaCore
    Author

    Wow, thanks for the quick response! I thought I was just doing something wrong.

    Is there a workaround for the time being?

  4. tonsky commented on Aug 6, 2019

    @tonsky
    Owner

    you can try explicitly pass fn as an argument to the rule. Might work, might not

  5. MyriaCore commented on Aug 7, 2019

    @MyriaCore
    Author

    Alright, that seems to work. Thanks!

    (d/q '[:find ?int
           :in ?intersection
           :where [(?intersection #{:a :b :c} #{:c :d :e}) ?int]]
         clojure.set/intersection))
    ;; => #{[#{:c}]}
    
    
    (d/q '[:find ?int
           :in % ?intersection
           :where (intersection-rule ?intersection #{:a :b :c} #{:c :d :e} ?int)]
      '[[(intersection-rule ?f ?s ?t ?int)
         [(?f ?s ?t) ?int]]]
      clojure.set/intersection))
    ;; => #{[#{:c}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions