在 Light Table 中使用 Datomic 时出现“无读取器功能”错误

2024-05-04

当我在 lighttable 中评估这段代码时:

(ns app.core
  (:require [datomic.api :refer [q] :as d]
            :reload-all))

(defn add-person
  [conn id]
  (d/transact conn [{:db/id #db/id[:db.part/user -1000001]
                     :person/id id}]))

I get:

clojure.lang.ExceptionInfo: No reader function for tag id
core.clj:4327 clojure.core/ex-info

有人知道发生了什么事吗?


本教程归功于斯图尔特·哈洛威 https://github.com/stuarthalloway and 鲍比·考德伍德 https://github.com/bobby:

(use :reload 'datomic.samples.repl)
(easy!)
(def conn (scratch-conn))

;; in data, use data literals for tempids
(def tx-data [{:db/id #db/id[:db.part/user]
               :db/doc "Example 1"}])
(transact conn tx-data)

;; in code, call tempid to create tempids
(let [id (tempid :db.part/user)
      doc "Example 2"]
  (transact conn [{:db/id id :db/doc doc}]))

;; same argument applies to functions:
;; use #db/fn literals in data
;; use Peer.function or d/function in code

;; broken, uses db/fn literal in code
(transact conn [{:db/id #db/id [:db.part/user]
                 :db/ident :hello
                 :db/fn #db/fn {:lang "clojure"
                                :params []
                                :code '(println :hello)}}])

;; corrected: used d/function to construct function
(transact conn [{:db/id (d/tempid :db.part/user)
                 :db/ident :hello
                 :db/fn (d/function {:lang "clojure"
                                     :params []
                                     :code '(println :hello)})}])
(d/invoke (db conn) :hello)

Source: https://github.com/Datomic/day-of-datomic/blob/master/samples/literals_vs_code.clj https://github.com/Datomic/day-of-datomic/blob/master/samples/literals_vs_code.clj

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Light Table 中使用 Datomic 时出现“无读取器功能”错误 的相关文章

随机推荐