[英]Clojure : access declared defrecord in another namespace
I am trying to access a "defrecord" from another ns and I get an error. 我试图从另一个ns访问“ defrecord”,但出现错误。 I am able to access a declared "def" and an declared constructor but not the "defredord". 我可以访问声明的“ def”和声明的构造函数,但不能访问“ defredord”。 This is the code: 这是代码:
(ns myapp.model)
(defrecord Person [fname lname])
(defn make-person [fname lname]
(->Person fname lname))
(def p1 (make-person "John" "Doe"))
(ns ibercode.core
(:require [myapp.model :as model]))
;;OK
(def p2 (model/make-person "John" "Doe"))
;;OK
(prn model/p1)
;;clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No
;;such namespace: ->model, compiling:
(def p3 (->model/Person "John" "Doe"))
Thanks R. 谢谢R。
You misunderstood ->
. 您误解了->
。 It is not syntax, but simply a naming convention. 它不是语法,而只是命名约定。
The name of the constructor function is ->Person
, so qualified, it is model/->Person
. 构造函数的名称为->Person
,因此限定为model/->Person
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.