Deprecated: Assigning the return value of new by reference is deprecated in /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php on line 90

Deprecated: Assigning the return value of new by reference is deprecated in /home/techmasa/public_html/wp-content/plugins/sem-recent-posts.php on line 942

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php:90) in /home/techmasa/public_html/wp-content/plugins/wordpress-automatic-upgrade/wordpress-automatic-upgrade.php on line 121

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/techmasa/public_html/wp-content/plugins/sem-cosmos-link/sem-cosmos-link.php:90) in /home/techmasa/public_html/wp-content/plugins/wordpress-automatic-upgrade/wordpress-automatic-upgrade.php on line 121
TechMasala - Technology Spice Rack » 2007 » March » 13

Archive for March 13, 2007

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.


Deprecated: Function ereg_replace() is deprecated in /home/techmasa/public_html/wp-content/plugins/sociable/sociable.php on line 64
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

Comments      Cosmos


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