我正在读一本关于clojure的书,我通过一个我不完全理解的例子来了..
这是repl中的代码:
user=> (repeatedly 10 (rand-int 10))
ClassCastException java.lang.Integer cannot be cast to clojure.lang.IFn clojure.core/repeatedly/fn--4705 (core.clj:4642)
user=> (repeatedly 10 (partial rand-int 10))
(5 0 5 5 2 4 8 8 0 0)
我的问题是:为什么partial
需要这里,以及它如何适合partial
定义、repeatedly
定义和语法。部分的 ...
Takes a function f and fewer than the normal arguments to f, and
returns a fn that takes a variable number of additional args. When
called, the returned function calls f with args + additional args.
那么这如何适应呢?