CSC/ECE 517 Fall 2011/ch1 1c ka: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 4: Line 4:
==Introduction==
==Introduction==


This article discusses the advantages of using closures over methods. There is a common argument over the necessity of closures and the way in which the closure behavior can be achieved by using anonymous classes. On the contrary, closures have more to their credit than what is the general perception that they increase the complexity and disrupt simplcity of the syntactic sugar. We try to identify some of the benefits of closures in this article.
This article discusses the advantages of using closures over methods. There is a common argument over the necessity of closures and the way in which the closure behavior can be achieved by using anonymous classes. On the contrary, closures have more to their credit than what is the general perception that they increase the complexity and disrupt simplcity of the syntactic sugar provided by the programming languages. We try to identify some of the benefits of closures in this article.


==Closures==
==Closures==


The concept of closures has been around for a long time. Closures were first implemented fully as a language feature in 1960 in the programming language Scheme. They were used to implement the lexically scoped first-class functions, that is closures can be treated as first-class objects. A closure is the function value which is treated as an object and which contains the references to the variable names in the lexical environment which was active when the closure was evaluated. In simple terms closures can be thought of as blocks of code which can be passed around as objects and which have access to the context in which they were first declared. This allows you to separate out the control structures. logical operators, loop operators etc. from the details of how they will be used. The fact that separates closures from normal objects is that they have access to the original context in which they are defined.
The concept of closures has been around for a long time. Closures were first implemented fully as a language feature in 1960 in the programming language Scheme. They were used to implement the lexically scoped first-class functions, that is closures can be treated as first-class objects. A closure is the function value which is treated as an object and which contains the references to the variable names in the lexical environment which was active when the closure was evaluated. In simple terms closures can be thought of as blocks of code which can be passed around as objects and which have access to the context in which they were first declared. This allows you to separate out the control structures. logical operators, loop operators etc. from the details of how they will be used. The fact that separates closures from normal objects is that they have access to the original context in which they are defined.

Revision as of 19:45, 5 September 2011

Wiki Chapter: CSC/ECE 517 Fall 2011/ch1 1c ka

Introduction

This article discusses the advantages of using closures over methods. There is a common argument over the necessity of closures and the way in which the closure behavior can be achieved by using anonymous classes. On the contrary, closures have more to their credit than what is the general perception that they increase the complexity and disrupt simplcity of the syntactic sugar provided by the programming languages. We try to identify some of the benefits of closures in this article.

Closures

The concept of closures has been around for a long time. Closures were first implemented fully as a language feature in 1960 in the programming language Scheme. They were used to implement the lexically scoped first-class functions, that is closures can be treated as first-class objects. A closure is the function value which is treated as an object and which contains the references to the variable names in the lexical environment which was active when the closure was evaluated. In simple terms closures can be thought of as blocks of code which can be passed around as objects and which have access to the context in which they were first declared. This allows you to separate out the control structures. logical operators, loop operators etc. from the details of how they will be used. The fact that separates closures from normal objects is that they have access to the original context in which they are defined.