On Thursday, March 9, 2017 at 6:41:39 PM UTC+1, William Byrd wrote: > > Hi Dmitrii! > > Here is an example of how the unifier for core.logic can be extended > to work with new data structures: > > > https://github.com/clojure/core.logic/wiki/Extending-core.logic-(Datomic-example) > > > In my message I was trying to ask whether anyone had used this > extension feature to implement unification over Clojure maps. And, if > so, whether that extension was useful for relational programming. >
I don't use Datomic but my library is modeled after it. I use it in http://culturia.one and a search engine. In culturia, there is no, transactionid (t) as in eavt ie. it's not persistent as Datomic is. My naming is (obviously!) different but I have the same concepts. It's called EAV <https://en.wikipedia.org/wiki/Entity%E2%80%93attribute%E2%80%93value_model> model. (BTW I don't understand how useful can be transactionid) I changed the name from eav to uav and now it's called *feature-space*. In particular, the unify function is implemented in fs:queryo: (define-public (fs:queryo u a v) ;; FIXME: maybe implement all query types ;; Attribute A can not be a variable (when (var? a) (throw 'feature-space "unsupported query type")) (lambda (s/c) (let ((u (walk u (car s/c))) (v (walk v (car s/c)))) (cond ;; U is a variable but not V ;; e.g. (queryo concept? 'concept/name "fruit") ((and (var? u) (not (var? v))) ((fs:findo u a v) s/c)) ;; V is a variable but not U ;; e.g. (queryo "P4X422" 'concept/name name?) ((and (not (var? u)) (var? v)) ((fs:refo u a v) s/c)) ;; V and U are not variable ;; e.g. (queryo "P4X422" 'concept/name "fruit") ((and (not (var? u)) (not (var? v))) ((fs:refo u a v) s/c)) ;; otherwise it's not supported ;; if u and v are variables it requires to scan all the database ((throw 'feature-space "unsupported query type")))))) The problem is the big throw at the beggining of the function that filter some kinds of unifications. Basically it's not possible to unify on attributes aka. it can not be variable. Here is a full example of querying, extracted from the test suite. This test creates two concepts (strawberry and fruit) and link them together using a "is good" relation. Reading "strawberry is a good fruit". And then asking the database, what is a good fruit: (test-check "microkanren fs:queryo" (with-env (env-open* "/tmp/wt" (list *feature-space*) "create") ;; fixture (let* ((concept/fruit (fs:add! (list '(name . "fruit")))) (concept/strawberry (fs:add! (list '(name . "strawberry")))) (concept/fig (fs:add! (list '(name . "fig")))) (link/strawberry-is-a-good-fruit (fs:add! (list `(from . ,concept/strawberry) `(name . "is good") `(to . ,concept/fruit)))) (link/fig-is-a-good-fruit (fs:add! (list `(from . ,concept/fig) `(name . "is good") `(to . ,concept/fruit))))) ;; execute query (sort (map car (run** (name?) (fresh (concept?? link?? a-fruit-that-is-good??) (fs:queryo concept?? 'name "fruit") (fs:queryo link?? 'to concept??) (fs:queryo link?? 'name "is good") (fs:queryo link?? 'from a-fruit-that-is-good??) (fs:queryo a-fruit-that-is-good?? 'name name?)))) string<))) '("fig" "strawberry")) > > Cheers, > > --Will > > > On Thu, Mar 9, 2017 at 6:44 AM, Dmitrii Kosarev > <[email protected] <javascript:>> wrote: > > Will, > > > > Can you tell more about ` extensible unifier handle maps ` or maybe send > a > > link? > > > > Happy hacking, > > Dmitrii > > > > On Thursday, March 9, 2017 at 8:46:32 AM UTC+3, William Byrd wrote: > >> > >> Does anyone know if the core.logic extensible unifier handle maps in > >> an interesting and useful way? > >> > >> Cheers, > >> > >> --Will > >> > >> On Wed, Mar 8, 2017 at 6:57 AM, Evgenii Moiseenko > >> <[email protected]> wrote: > >> > Association list was my first idea, and I actually use them > currently. > >> > > >> > But I am curious is there more efficient solution ? > >> > > >> > O(1) for lookup would be the best option, but intuitively it seems > hard > >> > to > >> > implement something like hash-tables in relational manner. > >> > Implementing a search tree seems to be more feasible. > >> > > >> > Nevertheless is there any research or papers in that area ? > (efficient > >> > relational map-like data structures). > >> > > >> > среда, 8 марта 2017 г., 5:21:42 UTC+3 пользователь Dan Friedman > написал: > >> >> > >> >> Use assv as a model to look up variable in an alist. > >> >> Then take that code of assv and write assvo. > >> >> > >> >> ... Dan > >> >> > >> >> On Tue, Mar 7, 2017 at 7:17 PM, Evgenii Moiseenko > >> >> <[email protected]> > >> >> wrote: > >> >>> > >> >>> I was wondering how the implementation of map-like data structure > >> >>> should > >> >>> look like in MiniKanren. > >> >>> I am writing an interpreter of imperative language in MiniKanren > and I > >> >>> need a data structure to represent a mappings between variables and > >> >>> their > >> >>> values. > >> >>> > >> >>> Is there any code that implements that ? > >> >>> > >> >>> -- > >> >>> You received this message because you are subscribed to the Google > >> >>> Groups > >> >>> "minikanren" group. > >> >>> To unsubscribe from this group and stop receiving emails from it, > send > >> >>> an > >> >>> email to [email protected]. > >> >>> To post to this group, send email to [email protected]. > >> >>> Visit this group at https://groups.google.com/group/minikanren. > >> >>> For more options, visit https://groups.google.com/d/optout. > >> >> > >> >> > >> > -- > >> > You received this message because you are subscribed to the Google > >> > Groups > >> > "minikanren" group. > >> > To unsubscribe from this group and stop receiving emails from it, > send > >> > an > >> > email to [email protected]. > >> > To post to this group, send email to [email protected]. > >> > Visit this group at https://groups.google.com/group/minikanren. > >> > For more options, visit https://groups.google.com/d/optout. > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "minikanren" group. > > To unsubscribe from this group and stop receiving emails from it, send > an > > email to [email protected] <javascript:>. > > To post to this group, send email to [email protected] > <javascript:>. > > Visit this group at https://groups.google.com/group/minikanren. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "minikanren" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/minikanren. For more options, visit https://groups.google.com/d/optout.
