2016-08-01 95 views
0

我是一个功能性编程的初学者,我试图打印一个迷宫。
这里是我的功能复发函数的参数号错误

(defn pprint-maze 
    [arr row col] 
    (loop [coll arr idx 0] 
    (match [idx] 
     [(_ :guard #(= (mod idx col) 0))] (println "") ; write a \n 
     :else (print "-"))      ; write a wall 
    (when (next coll) 
     (recur (next coll) (inc idx))))) 

我的功能需要收集和迷宫的大小和现在,只打印一个破折号和\ n在该行的末尾。 我有它的问题是: Exception in thread "main" clojure.lang.ArityException: Wrong number of args (1) passed to: core/pprint-maze/fn--4873/fn--4874

我觉得功能指出的是我的循环功能,以及相匹配的问题是有关(因为当我评论的匹配块,一切工作)。我认为这个匹配尝试用nil作为参数来调用循环函数(println函数的返回值)。

如何解决?

回答

7

传递给:guard的函数应该只有一个参数,该值被守护。你的函数采用零参数。

+2

...因为'#(...)'表格不包含'%'或'%1'标记。 – Thumbnail