Clojure closure

前端 未结 4 447
迷失自我
迷失自我 2021-01-31 19:43

the other day I was trying to come up with an example of closure in Clojure. I came up with and example I had seen before and thought it was appropriate.

Alas, I was tol

4条回答
  •  野的像风
    2021-01-31 20:29

    Function that returns function i.e higher order functions are nice examples of closure.

    (defn pow [n]
       (fn [x] (apply * (repeat n x))))
    
    (def sq (pow 2))
    (def qb (pow 3))
    

提交回复
热议问题