Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs/docs
diff options
context:
space:
mode:
authorMartin Baulig <martin@novell.com>2006-12-08 19:32:59 +0300
committerMartin Baulig <martin@novell.com>2006-12-08 19:32:59 +0300
commita6206432bb02a41b246156f58d9340589f913311 (patch)
tree121f198e0b4dd39b4f92fc5eb45051a6f8590a5f /mcs/docs
parentf9b20c56fdbdd614a72703dc5089b5913e3eff8e (diff)
Updated.
svn path=/trunk/mcs/; revision=69227
Diffstat (limited to 'mcs/docs')
-rw-r--r--mcs/docs/new-anonymous-design.txt35
1 files changed, 26 insertions, 9 deletions
diff --git a/mcs/docs/new-anonymous-design.txt b/mcs/docs/new-anonymous-design.txt
index 402654b5f82..5ceeee6c09a 100644
--- a/mcs/docs/new-anonymous-design.txt
+++ b/mcs/docs/new-anonymous-design.txt
@@ -99,17 +99,34 @@ The new code fundamentally changes the concept of CaptureContexts and
ScopeInfos. CaptureContext is completely gone while the ScopeInfo has
been completely redesigned.
-Each method containing anonymous methods introduces a "root scope" in
-which all other scopes are nested. This root scope is also called the
-anonymous method's host (class `AnonymousMethodHost' in anonymous.cs).
+Unfortunately, computing the "root scope" of an anonymous method is
+very difficult and was the primary reason for the update in late
+November 2006. Consider the following example:
+
+ ====
+ TestDelegate d = null;
+ for (int i = 1; i <= 5; i++) {
+ int k = i;
+ TestDelegate temp = delegate {
+ Console.WriteLine ("i = {0}, k = {1}", i, k);
+ sum_i += 1 << i;
+ sum_k += 1 << k;
+ };
+ temp ();
+ d += temp;
+ }
+ ====
+
+Note that we're instantiating the same anonymous method multiple times
+inside a loop. The important thing is that each instantiation must
+get the current version of `k'; ie. we must create a new instance 'k's
+helper-class for each instantiation. They all share `i's helper-class.
-The root scope deals with everything related to generics and also
-hosts the parameters and `this'. All other scopes are nested inside
-the root scope.
+This means that the anonymous method needs to be hosted in the inner
+helper-class.
-Note that if you have child scopes, they're all nested directly inside
-the root scope, not inside each other. Because of that, we don't need
-to link / reparent them.
+Because of that, we need to compute all the scopes before actually
+creating the anonymous method.
Anonymous Methods and Generics:
-------------------------------