gpt4 book ai didi

clojure - 在 Light Table 中使用 Datomic 时出现 "No reader function"错误

转载 作者:行者123 更新时间:2023-12-04 08:49:36 25 4
gpt4 key购买 nike

当我在 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}]))

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

有谁知道发生了什么?

最佳答案

本教程归属于 stuart hallowayBobby Calderwood :

(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)

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

关于clojure - 在 Light Table 中使用 Datomic 时出现 "No reader function"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15373486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com