Reputation: 7253
I'm a beginner with functional programming and I try to pretty print a maze.
Here is my function
(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)))))
My function takes the collection and the size of the maze and for now, just print a dash and a \n at the end of the row.
The problem I've it's :
Exception in thread "main" clojure.lang.ArityException: Wrong number of args (1) passed to: core/pprint-maze/fn--4873/fn--4874
I think the function pointed out is my loop function, and the problem is related to match (because when I comment the match block, everything work). I think that match try to call the loop function with nil as argument (the return of the println function).
How to solve that ?
Upvotes: 0
Views: 88
Reputation: 91837
The function passed to :guard
should take exactly one argument, the value being guarded. Your function takes zero arguments.
Upvotes: 7