From: Sam Sungshik Kong Date: 2004-10-20T03:04:20+09:00 Subject: Question about closure Hi, group! I am trying to understand what exactly a closure is. I'm kinda familiar with C#. In C# 2.0 (the next version that's coming out), there's a anonymous delegate. People say that it's a closure (See http://martinfowler.com/bliki/Closures.html). They even compare it with Ruby codes saying that closure is block. Is it true? When I saw the closure example in Ruby, it was not just a block. Here's a typical example of Ruby closure. def makeCounter var = 0 lambda do var +=1 end end c1 = makeCounter c1.call c1.call c1.call c2 = makeCounter puts "c1 = #{c1.call}, c2 = #{c2.call}" Here is what the above page(http://martinfowler.com/bliki/Closures.html) says... Closures have been around for a long time. I ran into them properly for the first time in Smalltalk where they're called Blocks. Lisp uses them heavily. They're also present in the Ruby scripting language - and are a major reason why many rubyists like using Ruby for scripting. Essentially a closure is a block of code that can be passed as an argument to a function call. .... In a language that has Closures, in this case Ruby, I'd write this. def managers(emps) return emps.select {|e| e.isManager} end This is just a block, right? Is it also a closure? I'm confused. Can somebody enlighten me? Sam