News for hackers. Stuff that matters.
Re:A lambda is not necessarily a closure by bbcbasic on Tuesday February 09, 2016 @12:44AM (#11063371)
Can someone explain why lambda expressions are being picked out?. I.e. why not say 'An expression is not necessarily a closure' as wouldn't this stuff apply to any old expressions, functions etc.

I am not a lisp person but thinking of this in terms of say C# or Haskell.

Re:A lambda is not necessarily a closure by Turing_Machine on Tuesday February 09, 2016 @01:41AM (#11063563)
They're being picked out because you see people do that all the time (i.e., calling an anonymous function a "closure"), while I don't recall ever seeing someone referring to a random expression as a closure.

I'm not overly fond of calling anonymous functions "lambdas", for that matter. Sure, several languages use the term lambda, but many do not. More specifically, "anonymous function" is much more descriptive than "lambda".

Re:A lambda is not necessarily a closure by nailer on Tuesday February 09, 2016 @05:58AM (#11064517)
Swift even does this officially: ALL lambdas are called closures, even though there's nothing being closed over.

Similarly, people refer to constructor functions that always return objects of the same class/prototype as factories, despite both the GoF patterns that popularised the term showing dynamic output. IIRC Angular JS misuses the term this way too.

AFAICT it's either genuine ignorance of how/why these words describe or some kind of weird demonstration of cleverness by using a particular term, regardless of whether it's applicable or not.

Re:A lambda is not necessarily a closure by Ono-Sendai on Tuesday February 09, 2016 @07:27AM (#11064801)
It's probably because, in an implementation of a staticly typed language, you have to treat all functions being passed around as closures. E.g. the type of a lambda expression needs to be one thing, and that is a closure. Whether or not any variables are actually closed over is irrelevant.
Re:A lambda is not necessarily a closure by nailer on Tuesday February 09, 2016 @10:18AM (#11065801)
Couldn't the type of a passed around function simply be 'function'? Why does it have to be inaccurate?
Re:A lambda is not necessarily a closure by Ono-Sendai on Tuesday February 09, 2016 @12:17PM (#11066879)
Well a function may in general have closed over arguments. Therefore it needs to be a closure. (If you have lexical scoping that is)
Re:A lambda is not necessarily a closure by dllthomas on Tuesday February 09, 2016 @01:39AM (#11063553)
Because lambdas are sometimes referred to as closures even where they don't close over anything. Other expressions generally aren't.
Re:A lambda is not necessarily a closure by sklogic on Tuesday February 09, 2016 @04:48AM (#11064271)
Lambda is easy to reason about, since it is guaranteed to not have any side effects. To juggle the other kinds of expressions like this you'd need a more elaborate purity analysis. So, lambda is a very easy prey for the DCE.

Also, there are some specific optimisations, like beta-reduction and closure inlining.