Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure:如何传递两组无界参数?_Clojure - Fatal编程技术网

Clojure:如何传递两组无界参数?

Clojure:如何传递两组无界参数?,clojure,Clojure,人为的例子来说明: (def nest1 {:a {:b {:c "foo"}}}) (def nest2 {:d {:e "bar"}}) 如果我想在任意级别连接这些巢穴,我可以显式地这样做: (conj (-> nest1 :a :b) (-> nest2 :d)) ; yields {:e "bar", :c "foo"} (conj (-> nest1 :a) (-> nest2 :d)) ; yields {:e "bar", :b {:c "foo"}}

人为的例子来说明:

(def nest1 {:a {:b {:c "foo"}}})
(def nest2 {:d {:e "bar"}})
如果我想在任意级别连接这些巢穴,我可以显式地这样做:

(conj (-> nest1 :a :b) (-> nest2 :d)) ; yields {:e "bar", :c "foo"}

(conj (-> nest1 :a) (-> nest2 :d)) ; yields {:e "bar", :b {:c "foo"}}
但是,如果我想创建一个函数,接受nest1和nest2的“深度”作为参数,该怎么办

; Does not work, but shows what I am trying to do
(defn join-nests-by-paths [nest1-path nest2-path]
   (conj (-> nest1 nest1-path) (-> nest2 nest2-path))
我可以这样称呼它:

; Does not work
(join-nests-by-paths '(:a :b) '(:d))
user> (macroexpand '(-> nest1 (:a :b)))
(:a nest1 :b)
这不管用。我不能简单地将每个“路径”作为列表传递给函数(或者我可以,但需要在函数中以不同的方式使用它)

有什么想法吗?蒂亚。。。 肖恩使用:

您的版本实际上正在执行以下操作:

; Does not work
(join-nests-by-paths '(:a :b) '(:d))
user> (macroexpand '(-> nest1 (:a :b)))
(:a nest1 :b)
正如你所说,这是行不通的

get-in
有朋友
assoc-in
update-in
,所有这些都用于处理地图的嵌套地图。clojure.conrtrib中的某个地方有一个
dissoc

(在Clojure中,在传递连续的事物组时,使用向量而不是引用列表更为惯用。)