21

我有以下数据结构:

{:file #<File /foo.bar>, :resolution {:width 1280, :height 1024}}

我想编写一个将:resolution键解构为width符号height的函数。就像是

(defn to-directory-name [{{:keys [width height]}} wallpaper]
  (str width "x" height))

解构可能会发生类似的事情吗?

谢谢。

4

2 回答 2

25

您必须首先解构 :resolution,然后获取宽度和高度:

{{:keys [width height]} :resolution}
于 2010-11-29T20:46:37.257 回答
5
(defn to-directory-name [{{width :width height :height} :resolution}] 
  (str width "x" height))

为我工作。

于 2010-11-29T20:46:04.580 回答