The Artima Developer Community
Sponsored Link

Agile Buzz Forum
C# 2.0 has Lexical Closures

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
C# 2.0 has Lexical Closures Posted: Apr 27, 2005 7:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: C# 2.0 has Lexical Closures
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement

I've been playing with the anonymous delegates in C# 2.0 and from all my tests, it seems that they are full lexical closures. They certainly aren't as easy to use as blocks in Smalltalk (you have to declare the delegate types and do casts at various times), but they do capture the local variables even when the method containing them returns.You can even have variables accessed by two delegates in the same method still share the same variables after the method returns. Calling the method again creates new variables which are distinct from the first call.

The one thing missing from C# closures which Smalltalk has is non-local returns. In Smalltalk, a return from a block causes a return from the whole method. This doesn't work in C#. Returning from a delegate returns back to the method and continues from there.

All said and done, though, I'm impressed that Microsoft has done as good a job at it as they have.

Read: C# 2.0 has Lexical Closures

Topic: Method lookup answers Previous Topic   Next Topic Topic: OCSTUG Puzzle Night

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use