gpt4 book ai didi

clojure - :or mean in Clojure destructuring? 是什么意思

转载 作者:行者123 更新时间:2023-12-01 08:51:22 24 4
gpt4 key购买 nike

法拉第扫描函数的来源( https://github.com/ptaoussanis/faraday/blob/master/src/taoensso/faraday.clj#L1197 )有一个我正在努力理解的解构形式......

(source far/scan)
(defn scan
"..."
[client-opts table
& [{:keys [attr-conds last-prim-kvs span-reqs return limit total-segments
filter-expr
segment return-cc?] :as opts
:or {span-reqs {:max 5}}}]]
...)

那是什么 :or {span-reqs {:max 5}}做?

最佳答案

它是默认值。更多详情请见http://clojure.org/guides/destructuring

(def my-map {:a "A" :b "B" :c 3 :d 4})
(let [{a :a, x :x, :or {x "Not found!"}, :as all} my-map]
(println "I got" a "from" all)
(println "Where is x?" x))
;= I got A from {:a "A" :b "B" :c 3 :d 4}
;= Where is x? Not found!

使用 :keys我们得到
(let [{:keys [a x] :or {x "Not found!"}, :as all} my-map]
(println "I got" a "from" all)
(println "Where is x?" x))

结果相同

关于clojure - :or mean in Clojure destructuring? 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41048547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com