“No reader function” error using Datomic in Light Table

只愿长相守 提交于 2019-12-09 16:40:20

问题


When I eval this code in 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

Anyone knows what is going on?


回答1:


This tutorial is attributed to stuart halloway and Bobby 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)

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




回答2:


It looks like there's an issue with trying to set :person/id. After the #db/id[:db.part/user -1000001] part, you've got a temporary id for adding data.

You should be able to start setting attributes for the entity using things like things like :person/name name.

If you're trying to create a "public id" type of thing, this blog post may be helpful.




回答3:


It's a problem in nREPL. The way I solved this is to start the REPL at the command line with:

lein repl

This will start a process that you can connect to from LightTable or Emacs. It will print information like:

nREPL server started on port 51395 on host 127.0.0.1
                             ^^^^^

Now in LightTable, Add a Connection -> Clojure Remote -> 127.0.0.1:XXXXX

The XXXXX should equal the port printed out by lein repl.

If you're in Emacs, cider has the same issue. Follow the same steps of starting lein repl, then use M-x cider-connect (it's default keybinding is C-c M-c).



来源:https://stackoverflow.com/questions/15373486/no-reader-function-error-using-datomic-in-light-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!