我是clojure的新手,我想创建一个函数,它返回某个Number的所有除数的向量.
例如:
[1 2 3]为6作为输入
(defn div [x seq]
(let [r (range 1 (+ (/ x 2) 1)) ]
(dotimes [i (count (range 1 (+ (/ x 2) 1) ))]
(cond
(= (mod x (nth r i )) 0)(print (conj seq (nth r i )))
))))
Run Code Online (Sandbox Code Playgroud)
此函数以下列格式返回输出:
[1] [2] [4] [5] [10] [20] [25] [50]为100,但我想在一个向量中获得输出.似乎seq变量不断被每个循环步骤覆盖.谁能解释这种行为并为我提供一个解决方法?
在此先感谢您的问候