我在讀一本關於Clojure的,我來過一個例子,我不完全瞭解..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.
那麼這怎麼適合?
我想,不知何故,這個問題是關於'(rand-int 10)'返回一個數字..# '#()'絕對看起來像一個更好的解決方案,語義 –