Many people are in fact confused, including some of those in the answer to the question you linked.
Let me reiterate my answer: a lambda is a language construct for (anonymous) function expressions, a closure is an implementation technique for making local functions first-class.
For example, in functional languages a named function definition
f x = x + 1 (* 1 *)
is typically just a short-hand for a lambda expression:
f = lambda x => x + 1 (* 2 *)
(Or vice versa, a lambda can be seen as a short-hand for an auxiliary local definition, e.g.,
lambda x => x + 1
is equivalent to a let-expression:
let f x = x + 1 in f
)
In other words, lambdas are merely syntax, they do not imply anything about semantics per se.
Closures, on the other hand, are a way to implement local functions, whether expressed as lambda or in named form. For example, consider:
g x = let h y = x + y in h (* 3 *)
or equivalently:
g x = lambda y => x + y (* 4 *)
(Functional languages even allow to abbreviate the latter to
g x y = x + y
)
Here the inner function refers to a local variable from the outer function (the parameter x
). An expression like g 2
will return a function, but the internal representation of this function cannot merely consist of the "code" of h
, it also has to include the information that x = 2
. The latter is called a closure environment, and the pair of closure environment and "code" is what is called a "closure". The name comes from mathematics: a function object "closes" over its environment (the names from outer scopes), in the sense of being a self-contained entity. In the implementation this is important in order to allow such functions to persist as stand-alone values even when the surrounding invocation has long returned.
So, as you can see, there are functions that are written as lambdas (e.g. 2 and 4 above), and there are functions that have to be represented as closures (e.g., 3 and 4 above), but one can occur without the other (e.g., 2 or 3). (Although languages with first-class functions typically treat all functions as closures, in the degenerate case they simply have an empty closure environment.)
The reason that people so often confuse the two notions is that many mainstream languages do not have a proper notion of local function that can refer to local variables without restriction (i.e., they have no closures). Some then started introducing lambda expressions as the only proper form of local function. And to make the difference extra clear, people talk about "closures" explicitly, to distinguish from other crippled forms of local functions, like they existed in some mainstream languages before.