Skip to content

Instantly share code, notes, and snippets.

@Jaretbinford
Created December 9, 2016 15:42
Show Gist options
  • Save Jaretbinford/564fd31d96ff9de2a40623ca93294ff8 to your computer and use it in GitHub Desktop.
Save Jaretbinford/564fd31d96ff9de2a40623ca93294ff8 to your computer and use it in GitHub Desktop.
Test for google group question
(ns intlong.core
(:import datomic.Util)
(require [datomic.api :as d]
[clojure.java.io :as io]))
(def db-uri "datomic:free://localhost:4334/intlong")
(d/create-database db-uri)
(def conn (d/connect db-uri))
; Schema
; I placed this in intlong.edn file
(def test-data-tx (read-string (slurp "/Users/jbin/Desktop/Jaret/Projects/workproof/merge/resources/intlong.edn")))
@(d/transact conn test-data-tx)
; data:
(def db (d/db conn))
(def data [{:group/root
{:group/sub
{:group/inner {:scalarDouble/a 1.0, :scalarDouble/b 2.0, :scalarDouble/c 3.0}}
}}])
@(d/transact conn data)
; Rules
(def rules
'[
;base case
[(exists-path? (?to) ?from ?depth)
[(ground 1) ?depth]
[?v ?to _]
[_ ?from ?v]
[?from :db/valueType :db.type/ref]]
; recursive case
[(exists-path? (?to) ?from ?depth)
[?from :db/valueType :db.type/ref]
[_ ?from ?v]
[?v ?via _]
[?via :db/valueType :db.type/ref]
(exists-path? ?to ?via ?subDepth)
[(+ 1 ?subDepth) ?depth]]
])
; Query
(def db (d/db conn))
(d/q '[:find ?from ?d0 ?d1 ?d2
:in $ % ?e0 ?e1 ?e2
:where
(exists-path? ?e0 ?from ?d0)
(exists-path? ?e1 ?from ?d1)
(exists-path? ?e2 ?from ?d2)]
; Query params
db, rules, :scalarDouble/a, :scalarDouble/b, :scalarDouble/c)
(def result *1)
(into [] result)
(def result *1)
(type (second (nth result 2)))
long
(type (second (nth result 3)))
long
(= (last result) (nth result 2))
=> true
(= (last result) (nth result 3))
=> true
(= (nth result 2) (nth result 3))
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment