This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[datomic.api :only [db q] :as d]) | |
;; DB setup | |
(def schema | |
[{:db/id #db/id[:db.part/db] | |
:db/ident :site/url | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Datomic example code | |
;; demonstrates various update scenarios, using a news database | |
;; that contains stories, users, and upvotes | |
;; grab an in memory database | |
(use '[datomic.api :only (q db) :as d]) | |
(def uri "datomic:mem://foo") | |
(d/create-database uri) | |
(def conn (d/connect uri)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[datomic.api :only [db q] :as d]) | |
(def schema | |
[{:db/doc "A persons name" | |
:db/id #db/id[:db.part/db] | |
:db/ident :name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[datomic.api :only [db q] :as d]) | |
(def schema | |
[{:db/doc "A persons name" | |
:db/id #db/id[:db.part/db] | |
:db/ident :name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[datomic.api :only [db q] :as d]) | |
(def schema | |
[{:db/id #db/id[:db.part/db] | |
:db/ident :num | |
:db/valueType :db.type/long | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
{:db/id #db/id[:db.part/db] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[datomic.api :only [db q] :as d]) | |
(def schema | |
[{:db/doc "A persons name" | |
:db/id #db/id[:db.part/db] | |
:db/ident :name | |
:db/valueType :db.type/string | |
:db/cardinality :db.cardinality/one | |
:db.install/_attribute :db.part/db} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmulti foo identity) | |
(defmethod foo 1 [n] | |
(recur (dec n))) | |
(defmethod foo 0 [n] | |
:ok) | |
(foo 1) ;; runs forever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require '[datomic.api :as d]) | |
(require '[clojure.pprint :refer [pprint]]) | |
(def uri "datomic:free://localhost:4334/git") | |
(def conn (d/connect uri)) | |
(def db (d/db conn)) | |
;; committers | |
(d/q '[:find ?email | |
:where | |
[_ :commit/committer ?u] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Given a class name, which methods have changed the most? | |
(->> (q '[:find ?name (count ?sha) | |
:in $ ?class-name | |
:where | |
[?codeq :java/class-name ?class-name] | |
[?mcodeq :codeq/parent ?codeq] | |
[?mcodeq :java/method ?codename] | |
[?codename :code/name ?name] | |
[?mcodeq :codeq/code ?code] | |
[?code :code/sha ?sha]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user=> (use 'clojure.core.logic.unifier) | |
user=> (prep '([?x])) | |
([<lvar:?x>]) ;; ok. ?x turned into an lvar | |
user=> (prep '([?x] . ?xs)) | |
([?x] . <lvar:?xs>) ;; fail. ?x is not an lvar |