Wednesday, January 24, 2018

Clojure: simple closure

Given a positive integer n, return a function (f x) which computes x^n.
(((fn [n] (fn [x] (apply * (repeat n x)))) 2) 16)
256
or
((partial (fn [n x] (apply * (repeat n x))) 2) 16)
256