IanG on Tap

Ian Griffiths in Weblog Form (RSS 2.0)

Blog Navigation

April (2018)

(1 item)

August (2014)

(1 item)

July (2014)

(5 items)

April (2014)

(1 item)

March (2014)

(1 item)

January (2014)

(2 items)

November (2013)

(2 items)

July (2013)

(4 items)

April (2013)

(1 item)

February (2013)

(6 items)

September (2011)

(2 items)

November (2010)

(4 items)

September (2010)

(1 item)

August (2010)

(4 items)

July (2010)

(2 items)

September (2009)

(1 item)

June (2009)

(1 item)

April (2009)

(1 item)

November (2008)

(1 item)

October (2008)

(1 item)

September (2008)

(1 item)

July (2008)

(1 item)

June (2008)

(1 item)

May (2008)

(2 items)

April (2008)

(2 items)

March (2008)

(5 items)

January (2008)

(3 items)

December (2007)

(1 item)

November (2007)

(1 item)

October (2007)

(1 item)

September (2007)

(3 items)

August (2007)

(1 item)

July (2007)

(1 item)

June (2007)

(2 items)

May (2007)

(8 items)

April (2007)

(2 items)

March (2007)

(7 items)

February (2007)

(2 items)

January (2007)

(2 items)

November (2006)

(1 item)

October (2006)

(2 items)

September (2006)

(1 item)

June (2006)

(2 items)

May (2006)

(4 items)

April (2006)

(1 item)

March (2006)

(5 items)

January (2006)

(1 item)

December (2005)

(3 items)

November (2005)

(2 items)

October (2005)

(2 items)

September (2005)

(8 items)

August (2005)

(7 items)

June (2005)

(3 items)

May (2005)

(7 items)

April (2005)

(6 items)

March (2005)

(1 item)

February (2005)

(2 items)

January (2005)

(5 items)

December (2004)

(5 items)

November (2004)

(7 items)

October (2004)

(3 items)

September (2004)

(7 items)

August (2004)

(16 items)

July (2004)

(10 items)

June (2004)

(27 items)

May (2004)

(15 items)

April (2004)

(15 items)

March (2004)

(13 items)

February (2004)

(16 items)

January (2004)

(15 items)

Blog Home

RSS 2.0

Writing

Programming C# 5.0

Programming WPF

Other Sites

Interact Software

Closure(s)

Thursday 19 February, 2004, 01:54 PM

In my recent blog on anonymous delegates, I mentioned I was sure I remembered reading an article saying that while inline delegates have access to variables in their enclosing scope, it would only be able to read those variables, not update them.

At the time, I was frustrated that I hadn't been able to locate the article. It has been nagging at me ever since. I craved, if you'll forgive the pun, closure.

Well I finally tracked it down. It was in Erik Meijer's blog. The reason I was unable to find it before is that it wasn't talking directly about C# after all. However, it was talking about closures and mutability, which is on-topic.

Moreover, although it doesn't mention C#, I think I can be excused for having concluded that it was talking in coded terms about a future version of C#. It talks about a 'hypothetical imperative language' which allocates its local variables on the stack. C# v1.x is an imperative language which allocates its local variables on the stack. Moreover, the blog was discussing the problems inherent in supporting closures in such a language. And back when I first read that blog, I knew that C# v2.0 was going to be getting closures (or rather, something very like them: anonymous delegates), so I assumed that this is what he was really talking about. (This was two and a half months before the PDC, so I didn't have access to Whidbey at that point.)

Not a completely unreasonable conclusion, but I was wrong nonetheless... Apparently Erik's 'hypothetical imperative language' was just that - hypothetical - and not in fact a coded reference to the forthcoming C# v2.0. As I mentioned in my earlier blog, C# v2.0 doesn't suffer from the problem Erik described. It allows closures to update variables too. It is able to do this because unlike in C# v1.x, local variables are no longer necessarily stored on the stack.

Copyright © 2002-2013, Interact Software Ltd. Content by Ian Griffiths. Please direct all Web site inquiries to webmaster@interact-sw.co.uk