📝Datomic syntax

tags

Datomic

  • basic query structure

    • s

      [:find ...
       :in ...
       :where ...]
      
  • input parameters

    • s

      [:find ...
       :in $ % ?scalar
               [?descructuring1 ?descructuring2]
               [?each ...] ;; ... is not omission
               [[?rel-from ?rel-to]]
       :where ...]
      
  • where

    • [?e :attr ?v] simple match

    • [?e :attr ?v ?tx] match transaction (fourth element)

    • [(< ?v1 ?v2)] predicate

    • [(func ?v1) ?res] transformation. func can be any clojure or host function (e.g., Java one)

    • (rule ?v1 ?v2) rule invocation. note missing square brackets

  • rules

    • rules are passed in as % argument

    • % is an array of rules, where each rule has the following form

      • _

        [(name ?param1 ?param2) ;; rule head
         [?param1 :attr ?param2] ;; rule body
         ]
        
    • the body of the rule can use all the same form as [where | from Datalog]

    • if there are multiple rules with the same name, they act as OR. they will be tried in order

  • Backlinks