這已經是可變參數(在支持一個以上的元數的意義上):
=> (doc reduce)
-------------------------
clojure.core/reduce
([f coll] [f val coll])
f should be a function of 2 arguments. If val is not supplied,
returns the result of applying f to the first 2 items in coll, then
applying f to that result and the 3rd item, etc. If coll contains no
items, f must accept no arguments as well, and reduce returns the
result of calling f with no arguments. If coll has only 1 item, it
is returned and f is not called. If val is supplied, returns the
result of applying f to val and the first item in coll, then
applying f to that result and the 2nd item, etc. If coll contains no
items, returns val and f is not called.
如果你成功了可變參數進一步(例如,允許集合的任意數字),則3參數的情況下將含糊 - 你的意思是通過一個初始值,或兩個不同的集合?
恕我直言,在多個不同方面製作功能variadic是一種反模式。僅僅因爲你可以用arity重載來改變函數的含義並不意味着它是一個好主意:你通常通過組成更高階的函數明確地達到相同的效果更好。
假設有這樣的「減少」變體。你會期待什麼論據,你通過它的功能? – Alex
累加器和'n'多個參數表示輸入序列的第一個元素,如'map'確實如此.. –
如果沒有提供,集合的第一個元素將作爲「reduce」的累加器的初始值,這不適用於可變情況。這並不是說你不容易編寫自己的需要初始值的版本,它只是不會有完全相同的語義。 – Alex