CSC/ECE 517 Fall 2010/ch1 1b gb: Difference between revisions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
Before diving into the differences of closures in Ruby viz a viz other languages, lets look at some traditional definitions of the same, and some history of closures to better understand the concept at hand. | Before diving into the differences of closures in Ruby viz a viz other languages, lets look at some traditional definitions of the same, and some history of closures to better understand the concept at hand. | ||
''A closure is a first-class function with free variables that are bound in the lexical environment.'' [http://en.wikipedia.org/wiki/Closure_%28computer_science%29 Closures:Wikipedia] | :''A closure is a first-class function with free variables that are bound in the lexical environment.'' [http://en.wikipedia.org/wiki/Closure_%28computer_science%29 Closures:Wikipedia] | ||
For the layman, lets break up the technical sounding definition into easier terms. Basically a first class function is something that can be passed onto as arguments to other functions i.e. it can behave like any other object or variables. A closure has its own variables with last as long as the scope of the closure and are independent of any other scope. (We will see later, how this is of importance) | For the layman, lets break up the technical sounding definition into easier terms. Basically a first class function is something that can be passed onto as arguments to other functions i.e. it can behave like any other object or variables. A closure has its own variables with last as long as the scope of the closure and are independent of any other scope. (We will see later, how this is of importance) | ||
Line 8: | Line 8: | ||
Another author of a Blog:[http://gafter.blogspot.com/2007/01/definition-of-closures.html A definition for closures] defines a closure as | Another author of a Blog:[http://gafter.blogspot.com/2007/01/definition-of-closures.html A definition for closures] defines a closure as | ||
''A closure is a function that captures the bindings of free variables in its lexical context.'' | :''A closure is a function that captures the bindings of free variables in its lexical context.'' | ||
It’s evident that this follows what we have written earlier. | It’s evident that this follows what we have written earlier. | ||
Line 16: | Line 16: | ||
Another writer states | Another writer states | ||
''A closure is a property associated with functions; when a function manipulates input and produces output which holds the features and characteristics of the input, then the function is said to possess (we should say 'satisfy' instead of 'possess') the closure property.''[http://linuxgazette.net/112/ramankutty.html Closures Definition] | :''A closure is a property associated with functions; when a function manipulates input and produces output which holds the features and characteristics of the input, then the function is said to possess (we should say 'satisfy' instead of 'possess') the closure property.''[http://linuxgazette.net/112/ramankutty.html Closures Definition] | ||
Landin is credited with introducing the term closure while referring to a ''lambda expression whose ‘Open Bindings’ or ‘free variables’ that have been bound ‘closed’ in a lexical environment resulting in a closed expression or ‘closure’''.[http://en.wikipedia.org/wiki/Closure_%28computer_science%29 Closures:Wikipedia] | Landin is credited with introducing the term closure while referring to a ''lambda expression whose ‘Open Bindings’ or ‘free variables’ that have been bound ‘closed’ in a lexical environment resulting in a closed expression or ‘closure’''.[http://en.wikipedia.org/wiki/Closure_%28computer_science%29 Closures:Wikipedia] |
Revision as of 00:30, 7 September 2010
What is a Closure?
Before diving into the differences of closures in Ruby viz a viz other languages, lets look at some traditional definitions of the same, and some history of closures to better understand the concept at hand.
- A closure is a first-class function with free variables that are bound in the lexical environment. Closures:Wikipedia
For the layman, lets break up the technical sounding definition into easier terms. Basically a first class function is something that can be passed onto as arguments to other functions i.e. it can behave like any other object or variables. A closure has its own variables with last as long as the scope of the closure and are independent of any other scope. (We will see later, how this is of importance)
Another author of a Blog:A definition for closures defines a closure as
- A closure is a function that captures the bindings of free variables in its lexical context.
It’s evident that this follows what we have written earlier.
Going further into layman’s terms, we could say that a closure is a kind of a ‘hidden function’ (similar construct in C, later) which is used by programmers in various languages to provide enhanced functionality in their programs/
Another writer states
- A closure is a property associated with functions; when a function manipulates input and produces output which holds the features and characteristics of the input, then the function is said to possess (we should say 'satisfy' instead of 'possess') the closure property.Closures Definition
Landin is credited with introducing the term closure while referring to a lambda expression whose ‘Open Bindings’ or ‘free variables’ that have been bound ‘closed’ in a lexical environment resulting in a closed expression or ‘closure’.Closures:Wikipedia
Since we are here to compare all types of closures with Ruby, lets look into the closure definition of the Ruby creator. Yukihiro Matsumoto defines closure as a Nameless function object and goes on to say that A closure object has code to run, the executable, and state around the code, the scope. Blocks and Closures in Ruby
References
<references/>