Talk:Closure (computer programming): Difference between revisions

Content deleted Content added
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 119:
 
Actually that java example on the anonymous class is overcomplicated for its result. The following code performs the same function without the need of creating an embedded runnable class. This is because the embedded Runnable classes run method is just called from the Thread classes run. Anyone who does threading in java knows this, which is why we can just extend thread instead of implementing Runnable. In such a case as this, it would be better formed code to just extend the thread into an anonymous, instead of creating an embedded runnable.
<sourcesyntaxhighlight lang="java">
class CalculationWindow extends JFrame {
private volatile int result;
Line 135:
}
}
</syntaxhighlight>
</source>
[[Special:Contributions/76.235.207.239|76.235.207.239]] ([[User talk:76.235.207.239|talk]]) 09:11, 29 May 2011 (UTC)
 
Line 675:
 
: To see a closure does not just "remember values" try:
<sourcesyntaxhighlight lang="python">
Python 3.1.2 (release31-maint, Sep 17 2010, 20:27:33)
[GCC 4.4.5] on linux2
Line 705:
>>> d()
2
</syntaxhighlight>
</source>
: —''[[User:Ruud Koot|Ruud]]'' 13:11, 2 April 2011 (UTC)
: Also, Finkel gives a pretty similar definition to the current one: "A procedure in combination with its nonlocal referencing environment is called a '''closure'''." And then continues with "Because this idea is unfamiliar to students who mainly use C (which has no nested procedures, and therefore no nonlocal referencing environments), I will present several examples." I think we should use the same approach. —''[[User:Ruud Koot|Ruud]]'' 19:31, 2 April 2011 (UTC)
Line 822:
I was reading this article and found this mismatch in section "Lexical environment". There is no <code>foo</code> function nor <code>f</code> or <code>g</code> variables. I think the text is referring to the example in section "Anonymous functions". Example and text follows:
 
<sourcesyntaxhighlight lang="ecmascript">
 
'use strict'
Line 836:
const runFunc = makeFunc();
runFunc(); //Closure
</syntaxhighlight>
</source>
 
Note how function<code>foo</code> and the closures referred to by variables <code>f</code> and <code>g</code> all use the same relative memory ___location signified by local variable <code>x</code>.