我正在练习教程 Clojure Design Patterns - Observer
在“观察者”主题中,没有用户和应用函数构造的方法。当我尝试解决这些问题时,我遇到了错误。
问题在于apply函数将对象转换为seq。另一个问题是,当apply函数具有多个字段时,它会将对象作为多个参数获取。有什么想法吗?
我的无效代码是
(ns observer.core)
(defrecord person [name balance])
(def user (person. "alan" 434))
(apply
(fn [& u]
(println u)
(println (str (:name u) " and " (:balance u))))
user)
(println "The end")
输出
([:name alan] [:balance 434])
and
The end
observer.core>
我的问题是我们应该为用户数据使用哪种程序结构来实现链接文章中所示的解决方案。我在Stackoverflow上对本文提出了另一个问题,但在那里我只问了一张地图。在这个问题中,我实际上提到了一些可以建议的数据结构或类型。我不确定地图。