ribelo / doxa

The Unlicense
232 stars 8 forks source link

Documentation example for nested matching #8

Closed stevebuik closed 3 years ago

stevebuik commented 3 years ago

I'm trying to make this (filtering using non-entity nested data) work...

(let [person1 {:person/id 1
                 :gender    "MALE"
                 :name      "Bob"
                 :face      {:eyes "BLUE"}}
        person2 {:person/id 2
                 :gender    "FEMALE"
                 :name      "Joanne"
                 :face      {:eyes "GREEN"}}
        db (dx/commit (dx/create-dx) [[:dx/put person1]
                                      [:dx/put person2]])]
    [(dx/q [:find ?person ?name ?eye-color
            :in ?table ?color
            :where
            [?table ?person :name ?name]
            [?table ?person :face (m/some {:eyes ?eye-color})]
            ;[(= ?color ?eye-color)]
            ]
           db :person/id "BLUE")])

when I uncomment the [(= ?color ?eye-color)] line, it fails to parse. it seems like you cannot use a var from :in unless it is already bound in the :where

I tried [?table ?person :face (m/some {:eyes ?color})] but this didn't filter correctly.

  1. can you help me (meander noobie) make this work
  2. this might also be a useful test and/or doc example for others
ribelo commented 3 years ago

In general, datalog does not support nesting, but there is no problem to handle it. What you wrote is ok and should work, but there is a bug.

stevebuik commented 3 years ago

oh ok. it's good news that I am not going crazy. I looked at this too long :)

Can you comment here again when you fix that bug? Then I'll start again on my testing of Datalog.

My tests for pull are all working now so that is great progress.

ribelo commented 3 years ago

done ; )

stevebuik commented 3 years ago

can confirm this is working for me now.