[英]How can I access a record in a library in Clojure?
I'm writing a library that implements a protocol and trying to access the record outside the namespace. 我正在编写一个实现协议的库,并尝试访问命名空间外的记录。
storage.clj
contains the record: storage.clj
包含记录:
(defrecord FrienduiStorage []
f-glob/FrienduiStorage
(get-all-users [this]
(db/get-all-users)))
I require it like so [sventechie.friendui-mysql.storage :refer :all]
. 我需要它像[sventechie.friendui-mysql.storage :refer :all]
。 Then instantiate it like this (def FrienduiStorageImpl (->FrienduiStorage))
but this doesn't work: (get-all-users (FrienduiStorageImpl))
"RuntimeException: Unable to resolve symbol: get-all-users in this context". 然后像这样实例化它(def FrienduiStorageImpl (->FrienduiStorage))
但这不起作用: (get-all-users (FrienduiStorageImpl))
“RuntimeException:无法解析符号:在此上下文中获取所有用户”。 What am I doing wrong? 我究竟做错了什么?
The full library repo is at ( http://github.com/sventechie/friendui-mysql/ ). 完整的库仓库位于( http://github.com/sventechie/friendui-mysql/ )。 I've made a minimal usage example ( http://github.com/sventechie/friendui-mysql-example/ ). 我做了一个最小的用法示例( http://github.com/sventechie/friendui-mysql-example/ )。
To formalize @mavbozo's comments to your question into an answer, you need to add an import to the regular class 要将@ mavbozo对您的问题的评论形式化为答案,您需要向常规类添加导入
So definition is 所以定义是
(ns sventechie.friendui-mysql.storage)
(defrecord FrienduiStorage [])
and usage is: 用法是:
(ns somewhere.else
(:require [sventechie.friendui-mysql.storage :refer :all])
(:import [sventechie.friendui-mysql.storage.FrienduiStorage]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.