is this partial function a closure?

Viewed 425

I am discussing closure with a friend and he thinks (partial + 5) is a closure. But I think a closure is a function closing over a free variable, for example

(let [a 10]
  (defn func1 [x] (+ x a))
)

then func1 is a closure. But in this case 5 is not a free variable. So which is the right answer?

2 Answers

(partial + 5) is an anonymous function or "lambda".

Anonymous functions are often¹ called "closures" but it's an abuse of the term ; see the discussion in "What is the difference between a 'closure' and a 'lambda'?"


[¹] Maybe because in most popular languages that support them, closures and anonymous functions are created using the same language features - which renders them undistinguishable at first glance.

Related