Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 在输入上递归重复函数n次(无循环重复)_Clojure - Fatal编程技术网

Clojure 在输入上递归重复函数n次(无循环重复)

Clojure 在输入上递归重复函数n次(无循环重复),clojure,Clojure,我知道我可以用loop和recur解决我的问题,但这似乎是一个非常简单(常见?)的操作,我想知道在clojure中是否没有单一的函数,或者使用loop/recur来解决这个问题。我找了一下,但没找到什么 我正在寻找的函数如下 (the-function n input some-function) 其中n是递归调用输入上某个函数的时间数 一个简单的例子是: (the-function 3 1 (fn [x] (+ x 1))) => 4 Clojure有类似的东西吗 最好的问候你想要

我知道我可以用loop和recur解决我的问题,但这似乎是一个非常简单(常见?)的操作,我想知道在clojure中是否没有单一的函数,或者使用loop/recur来解决这个问题。我找了一下,但没找到什么

我正在寻找的函数如下

(the-function n input some-function)
其中n是递归调用输入上某个函数的时间数

一个简单的例子是:

(the-function 3 1 (fn [x] (+ x 1)))
=> 4 
Clojure有类似的东西吗


最好的问候

你想要的基本上是
迭代
。它将生成一个无限序列的函数对种子输入的重复应用。因此,要复制您在这里描述的行为,您可以这样写:

(nth (iterate some-function input) n)
试试这个:

(defn your-iterate-fn [times init-param the-fn] 
    (last (take (inc times) (iterate the-fn init-param))))
(your-iterate-fn 3 1 (fn [x] (+ x 1)))
==> 4

好极了,正是我要找的。它一直清晰可见,但我仍然忽略了它。谢谢,这也有效,但上面的第n个解决方案更优雅了一点。:)