Closures

When an expression or a block of code is passed as a parameter to a function or method then the piece of code that gets passed is called a closure in programming language terms. Closure is not something new and has been supported in programming languages like Smalltalk, Lisp, Python etc. A closure is like nameless functions within functions. Closures are supported in Ruby and are called blocks. A simple closure example in Ruby would be,

5.times {puts “Hello World”}

This prints “Hello World” five times. This code is the equivalent of the below code,

for i in 1..5
puts “Hello World”
end

Complex closures can be tricky to understand but once a developer gets the point how it works it could simplify or complex depending on the problem in hand and where it is applied. Some programming languages like Java don’t support closures yet. Is closures really handy or inconvenience? Read this article “Crossing borders: Closures” for more insights.

Blink this Closures at blinklist.com    Bookmark Closures at blogmarks    Bookmark Closures at del.icio.us    Digg Closures at Digg.com    Fark Closures at Fark.com    Bookmark Closures at Furl.net    Bookmark Closures at NewsVine    Bookmark Closures at reddit.com    Bookmark Closures at Simpy.com    Bookmark Closures at Spurl.net    Bookmark Closures with wists    Bookmark Closures at YahooMyWeb

      Cosmos

Leave a Comment

authimage


Creative Commons License  This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.