Why does Clojure recur think it should have only one argument?

Edit:

The answer to this question: I looked at functions, not loop parameters.

In the second of the following two functions, I cannot understand why recur believes that it should only allow one argument.

CompilerException java.lang.IllegalArgumentException: Invalid count argument to return, expected: 1 args, got: 2, compilation: (/ home / cnorton / projects / clojure / clj_in_action / mr1 / src / mr1.clj: 84)

I do not see what is wrong.

(defn determine-rover-move [rover-coord mov] (println rover-coord mov) (cond (= \L mov) (assoc rover-coord 0 (adj-compass-posL (first rover-coord))) (= \R mov) (assoc rover-coord 0 (adj-compass-posR (first rover-coord))) (= \M mov) (mov-rover rover-coord) )) (defn execute-each-move [moves rover-coord] (loop [mov moves] (if (nil? mov) rover-coord (recur (rest moves) (determine-rover-move rover-coord mov))))) 
0
source share
1 answer

The important part is here:

 (loop [mov moves] ...) 

This piece of code associates mov with moves from the scope of an external function. Using recur goes inside the loop , though, so recur expects only one parameter according to the definition of loop .

+3
source

Source: https://habr.com/ru/post/1412014/


All Articles