I am trying to write a program that checks if a number is perfect or not using clojure. I am very new to clojure or any other functional programming language. When I remove the if statement on the 5th line it works fine. But I need to check if i divides the number or not. And that is my problem. Please check my function below and tell me why its returning nil. no matter what I change keeps returning nil. And if any one can go line by line and explain what each line is doing that would help too. Thanks
(defn perfect [number] (loop [i 1 sum 0] (if (< i number) (recur (+ i 1) (if (= (mod number i) 0) (+ sum i))) sum)))
Aucun commentaire:
Enregistrer un commentaire