我有以下功能定义用于map-edit
(def map-edit
(fn [m lst k f]
(if (car lst)
(assoc m
(car lst)
(map-edit (get m (car lst) {}) k f))
(assoc m k (f (get m k))))))
当我尝试在我的repl中调用此函数时
(map-edit {} (list "oeu") "oeuoeu" (fn [q] "oeu"))
我收到了Arity的错误
ArityException Wrong number of args (3) passed to: core/map-edit clojure.lang.AFn.throwArity (AFn.java:429)
为什么我认为我只传递了3个参数?
; CIDER 0.8.2 (Java 1.8.0_121, Clojure 1.8.0, nREPL 0.2.12)
答案 0 :(得分:6)
假设您有这些定义
(def car first)
(def cdr rest)
对map-edit的递归调用仅使用该行可能应该为
的3个参数(map-edit (get m (car lst) {}) (cdr lst) k f))
确保下次更仔细地查看错误的堆栈跟踪。
答案 1 :(得分:0)