Skip to content

Extending core.logic (Datomic example)

swannodette edited this page May 19, 2012 · 21 revisions

core.logic was designed with extensibility in mind. You may want to unify your own custom data structures - not only the ones provided for by Clojure. To see how this can be done we'll use Datomic Datum's as an example.

For the following examples, assume the following ns declaration:

(ns example
  (:use [datomic.api :only [db q] :as d])
  (:require [clojure.core.logic :as l]))

In order for your custom data structure to participate in unification it must implement IUnifyTerms. For Datomic Datum's this looks like the following:

(extend-type datomic.db.Datum
  l/IUnifyTerms
  (l/unify-terms [u v s]
    (unify-with-datum v u s)))

u is of course the Datum, v is other structure being unified with and s is the substitutions map.

Clone this wiki locally