gpt4 book ai didi

interface - 我如何访问 Clojure 库中的记录?

转载 作者:行者123 更新时间:2023-12-03 08:13:29 24 4
gpt4 key购买 nike

我正在编写一个实现协议(protocol)的库,并尝试访问命名空间之外的记录。

storage.clj 包含记录:

(defrecord FrienduiStorage []
f-glob/FrienduiStorage
(get-all-users [this]
(db/get-all-users)))

我这样要求它 [sventechie.friendui-mysql.storage :refer :all]。然后像这样实例化它 (def FrienduiStorageImpl (->FrienduiStorage)) 但这不起作用: (get-all-users (FrienduiStorageImpl))解析符号:在此上下文中获取所有用户”。我做错了什么?

完整的库存储库位于 ( http://github.com/sventechie/friendui-mysql/)。我做了一个最小使用示例 ( http://github.com/sventechie/friendui-mysql-example/ )。

最佳答案

要将@mavbozo 对您问题的评论形式化为答案,您需要向常规类添加导入

所以定义是

(ns sventechie.friendui-mysql.storage)
(defrecord FrienduiStorage [])

用法是:

(ns somewhere.else
(:require [sventechie.friendui-mysql.storage :refer :all])
(:import [sventechie.friendui-mysql.storage.FrienduiStorage]))

关于interface - 我如何访问 Clojure 库中的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29159515/

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