closures

What is the difference between a closure and a nested closure?

What is the difference between a closure and a nested closure? A good explanation with examples would be helpful. ...

Whats the difference between C# delegates, Dynamic Proxy, Closures and function pointers?

What are useful definitions for the common methods of passing a method or function as data, such as: Delegates Closures Function pointers Invocation by dynamic proxy and First class methods? ...

Closures for anonymous methods in C# 3.0

Why do closures exist for anonymous methods? Why not just pass state into the method without the overhead of a new class being generated with the closure variables being copied in? Isn't this just a throwback to "making everything global?" Someone talk me down, I feel like i'm missing something here... ...

JavaScript function aliasing doesn't seem to work

I was just reading this question and wanted to try the alias method rather than the function-wrapper method, but I couldn't seem to get it to work in either Firefox 3 or 3.5beta4, or Google Chrome, both in their debug windows and in a test web page. Firebug: >>> window.myAlias = document.getElementById function() >>> myAlias('item1') >...

Is this method of converting an asynchronous method to a synchronous one correct?

I've got a method implemented using the Event-based Asynchronous method pattern. I also want to offer a synchronous version of that method, but don't want to re-write it (because the method involves a call to WCF from Silverlight, the Async version has to be the primary method). I've come up with the following generic method to convert ...

Ruby blocks, java closures in C++

I am developing a program where I find myself doing this like this a lot: void Model::SetCollideMode( const std::string &m ) { Body *body; std::map<std::string, Body* >::iterator iter; for (iter=this->bodies.begin(); iter!=this->bodies.end(); iter++) { body = iter->second; body->SetCollideMode( m ); } } I have sev...

Why can't I roll a loop in Javascript?

I am working on a web page that uses dojo and has a number (6 in my test case, but variable in general) of project widgets on it. I'm invoking dojo.addOnLoad(init), and in my init() function I have these lines: dojo.connect(dijit.byId("project" + 0).InputNode, "onChange", function() {makeMatch(0);}); dojo.connect(dijit.byId("project" ...

How to call functions that are nested inside a JQuery Plugin?

My goal is to be able to call functions that are inside my JQuery plugin. What is the correct syntax? For example, this does not work: <a href="#" id="click_me">Click Me</a> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; <script> (function($) { $.fn.foo = function(options) { ...

javascript private variables access problem

Hi, this one for the javascript gurus: I'm experimenting with a new javascript framework. Its structure is inspired by none other than the mighty jQuery. It has a global variable called $j, and .. oh, just see it in action: /* file: jfoo.js */ $j = new (function(){ var modules=[]; this.loadModule = function(mod) { modul...

Why does it say xxx is not a function

Hi All, why is this not ok? aContract = function(){}; aContract.prototype = { someFunction: function() { alert('yo'); }, someOtherFunction: some$Other$Function }; var some$Other$Function = function() { alert('Yo yo yo'); }; var c = new aContract(); c.someFunction(); c.someOtherFunction(); Firebug says c.some...

jQuery closure & object property access

Hi, Can anyone tell me how to get access to variable "a" here: var test = { a: 3, init: function() { $("body").click(function() { alert(a); }); } }; test.init(); This doesn't work either: alert(this.a); Thanks in advance. ...

Easiest way to build a tree from a list of Ancestors

In my heart, I feel that there must be a super simple recursive solution to this, but I cannot immediately grok it. I have a tree stored in SQL as a closure table. The tree looks like: (1 (2 (3), 4)), and the languages are MySQL's SQL and PHP 5.3. The closure table is thus: +----------+------------+ | ancestor | descendant | +-------...

Output from anonymous classes?

How can I get output from Java anonymous classes? In .Net I would use closures. executor = Executors.newSingleThreadExecutor(); final Runnable runnable = new Runnable() { public Exception exception; @Override public void run() { try { doSomething(); } catch (Exception exception) { // I'd like to report thi...

In Php 5.3.0 what is the Function "Use" Identifier ? Should a sane programmer use it?

I'm checking out some php 5.3.0 features and ran across some code on the site that looks quite funny: public function getTotal($tax) { $total = 0.00; $callback = /* This line here: */ function ($quantity, $product) use ($tax, &$total) { $pricePerItem = constant(__CLASS__ . "::PRICE_" . ...

Is Netbeans 6.7 incapable of debugging Groovy closures in a Grails application?

It seems to be possible to debug Grails applications in the recently released Netbeans 6.7, even if not directly through the menus. However, is it really so, that it's still not possible to set breakpoints in closures, as hinted in this thread? I'm currently quite baffled by this, since I find it hard to believe they still haven't imple...

Can someone define what a closure is in real world language?

Possible Duplicate: What is a Closure? I read more and more about closures but I don't really get what it is from a practical standpoint. I read the wikipedia page on it but it doesn't really clear anything up for me because I have more of a practical background in programming (self taught) as opposed to a computer science backg...

Question on Scala Closure (From "Programming in Scala")

I don't understand why authors said that Code Listing 9.1 from "Programming in Scala" use closure. In chapter 9, they show how to refactor code into more less duplicated form, from this original code: object FileMatcher { private def filesHere = (new java.io.File(".")).listFiles def filesEnding(query: String) = for (file <- file...

Static Variables in R

I have a function in R that I call multiple times. I want to keep track of the number of times that I've called it and use that to make decisions on what to do inside of the function. Here's what I have right now: f = function( x ) { count <<- count + 1 return( mean(x) ) } count = 1 numbers = rnorm( n = 100, mean = 0, sd = 1 ) fo...

Accessing 'self' object in closure

Hello, I've got following problem: (c#) There is some class (IRC bot), which has method, which needs result of some event for complete (through it could be asynchronous). Maybe not clear: // simplified class IRC { void DoSomeCommand() { OnListOfPeopleEvent += new Delegate(EventData e) { if (e.IsForMe) { ReturnToUserSom...

What is the exact definition of a closure?

I've read through previous topics on closures on stackflow and other sources and one thing is still confusing me. From what I've been able to piece together technically a closure is simply the set of data containing the code of a function and the value of bound variables in that function. In other words technically the following C func...