Clojure 如何从defrecord创建集合?

Clojure 如何从defrecord创建集合?,clojure,Clojure,我有: 我想有一个单一的“构造”功能,它将记录人类或宇宙飞船,并返回一组键作为实际记录键: (defrecord human-being [uuid first-name last-name genome-sequence]) (defrecord space-ship [uuid ship-type engines home-world captain]) 我不仅仅想要这两张唱片。我需要能够删除任何记录,并获得类似的输出 我有一种感觉,我应该为此使用宏,但这让我有点害怕……考虑到问题的关键

我有:

我想有一个单一的“构造”功能,它将记录人类或宇宙飞船,并返回一组键作为实际记录键:

(defrecord human-being [uuid first-name last-name genome-sequence])

(defrecord space-ship [uuid ship-type engines home-world captain])
我不仅仅想要这两张唱片。我需要能够删除任何记录,并获得类似的输出


我有一种感觉,我应该为此使用宏,但这让我有点害怕……

考虑到问题的关键是“如何将Defrecord转换为map”,我可以想出4种大致相同的方法

(def john (human-being. "ABC123" "John" "Smith" "QWERTY"))
(def enterprise (space-ship. "ZXC123" "Galactic" "Warp" "Earth" "Picard"))

(constructFunc john) --returns--> {:uuid "ABC123" :first-name "John" :last-name "Smith" :genome-sequence "QWERTY"}

(constructFunc enterprise) --returns--> {:uuid "ZXC123" :ship-type "Galactic" :engines "Warp" :home-world "Earth" :captain "Picard"}

我不确定我是否理解,“我不只是想要这两个def记录”,所以你想要一组地图<代码>(进入(散列集)(映射#(进入{}%)[john enterprise])也许?所以我想有一个通用函数,我可以删除任何类型的defrecord(可能还没有定义),它只是吐出一个映射…
#(进入{}%)
这样做(或者如果你喜欢命名的fn
(defn->map[r](进入{}r))
)非常感谢,非常简单!有没有办法将defrecord的“type”获取为字符串。。。例如:(记录企业号)——>“太空船”?
(约翰号)
或类似型号
; direct - but this is stricly speaking not 'a function'
(into {} john)

; anonymous
( #(into {} %) john )

; named 
(defn ->map [r] 
  (into {} r))
(->map john)

; via composition/partial
( (partial into {}) john)    

; all of them return
{:uuid "ABC123", :first-name "John", :last-name "Smith", :genome-sequence "QWERTY"}