我正在尝试找到一种方法来构建一个参数来传递给这个函数(它是托盘的一部分):
(defn node-spec [& {:keys [image hardware location network qos] :as options}]
{:pre [(or (nil? image) (map? image))]}
options)有效的是这种用法:
(node-spec :location {:location-id "eu-west-1a"}, :image {:image-id "eu-west-1/ami-937474e7"} :network {})但是其中的:location和:image位对于我要提供的所有机器都是通用的,而:network {}位对于每个节点是不同的。所以我想把常见的部分去掉,然后做一些如下的事情:
(def my-common-location-and-image {:location {:location-id "eu-west-1a"}, :image {:image-id "eu-west-1/ami-937474e7"}} )
(node-spec (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))
(node-spec (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))但这不管用。合并后的映射被解析为缺少其值的单个键。所以我试着
(node-spec :keys (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))和
(node-spec :options (merge {:network {:security-groups [ "group1" ] }} my-common-location-and-image ))但这也不起作用。我觉得我是在试图反转或克服node-spec参数中的解构。我做错了什么?或者我的目标是不可能分解出一些键/值对?
发布于 2013-02-23 02:14:43
问题是node-spec函数需要的是序列而不是映射。这是因为被解构的是可以按键-值对分组的一系列事物。
所以,不是传递这个:
{:image {:image-id "eu-west-1/ami-937474e7"}, :location {:location-id "eu-west-1a"}, :network {:security-groups ["group1"]}}我们需要传递以下内容:
'(:image {:image-id "eu-west-1/ami-937474e7"} :location {:location-id "eu-west-1a"} :network {:security-groups ["group1"]})这意味着这将会起作用:
(apply node-spec
(reduce concat
(merge {:network {:security-groups ["group1"]}}
my-common-location-and-image)))https://stackoverflow.com/questions/15029183
复制相似问题