The 'Lexical Closure' essay (http://www.jsoftware.com/jwiki/Guides/Lexical%20Closure) mentioned in this thread declares lexical closures to be 'incompatible with the functional programming model'. Such a statement is incorrect.
If a function returns different values for the same arguments, it is not because closures are involved but because that function has a changeable state. The latter results from assigning the same name different values at different times (other than passing a value to a parameter), or from data objects themselves being mutable. If there are no assignments at all (as in a purely functional language), or if single assignments are only allowed, and if each piece of data is immutable, then closures do no harm to functional behaviour, and are actually a very useful functional programming facility. To see that closures are merely a language convenience that perfectly fits the functional programming model, note that every implicit closing over a non-local variable can be replaced by an explicit function (creation and) application. (Exactly the same holds of eliminating properly local variables from a function.) So we are always guaranteed to end up with pure lambda expressions. Of course, doing such transformations manually is tedious and leads to cluttered and less efficient programs. But local variables, function nesting and context capturing, i.e. closures, are so hugely useful that most functional and many other languages support them natively. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
