Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Clojure equivalent of inject:into: in Smalltalk?

I'm trying to learn Clojure but my synapses seem to be hard-wired to Smalltalk.

What's the equivalent of this function?

[:n :k | (1 to: k) inject: 1 into: [:c :i | c * (n - k + i / i)]]
  • this is the binomial coefficient for n, k - also known as "choose" function, representing the number of combinations of n things taken k times
like image 312
Steve Wart Avatar asked Jan 28 '11 18:01

Steve Wart


1 Answers

The clojure equivalent of lst inject: s into: f is (reduce f s lst)

like image 166
sepp2k Avatar answered Oct 21 '22 12:10

sepp2k