Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
例如,如果我有:
(defrecord Item [name cost])
我怎么能转换["ball" 10]成{:name "ball", :cost 10}?
["ball" 10]
{:name "ball", :cost 10}
user=> (defrecord Item [name cost]) user=> (apply ->Item ["ball" 10]) #user.Item{:name "ball", :cost 10}
简短解释发生了什么。(->Item "ball" 10)是从给定参数创建记录的语法之一。它与 相同(Item. "ball" 10)。在您的情况下,您有参数向量,因此我们(apply fn args-vector)用来处理。
(->Item "ball" 10)
(Item. "ball" 10)
(apply fn args-vector)