New drop of C# 3.0/LINQ

Don Box's Spoutlet

Syndication

 
Favorite new feature: LambdaExpression.Compile
 
Expression<Func<int, int>> expr = a => a + 3;
Console.WriteLine(expr); // prints "a => Add(a, 3)"
Func<int, int> func = expr.Compile(); // LCG's an MSIL method from the expr
Console.WriteLine(func(4)); // prints "7"
 
Which of course is equivalent to:
 
(define expr '(lambda (a) (+ a 3)))
(display expr)
(define func (eval expr (scheme-report-environment 5)))
(display (func 4))
 
 
 

Posted May 11 2006, 01:41 PM by don-box

Comments

Isaac Gouy wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 9:57 AM
Who do I tell about install problems?

"An error occurred while applying security settings. Power Users is not a valid user or group. This could be a problem with the package, or a problem connecting to a domain controller on the network. Check your network connection and click Retry, or Cancel to end the install."
IDisposable@gmail.com (Marc C. Brooks) wrote Re: New drop of C# 3.0/LINQ
on 05-11-2006 10:53 AM
I still can't seem to like the lambda syntax. Something like

Expression<Func<int, int>> expr = with(a) {a + 3 };

Would look much better to me.
Don Box wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 12:17 PM
Isaac,

Send mail to tliang at microsoft dot com.

Ting is waiting for your mail.

DB
Ting Liang wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 1:06 PM
Isaac, please refer to
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=394174&SiteID=1

for a solution/workaround to the security settings issue.

tliang@microsoft.com
Barry Kelly wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 2:00 PM
Excellent! I asked about this on the day I first found out about LINQ:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=91003&SiteID=1

That's good news.
Isaac Gouy wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 2:37 PM
Thanks, on Home XP I created "Power User" installed and then deleted "Power User".
Local variable type inference works fine.
Isaac Gouy wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 3:08 PM
var expr = a => a + 3;

"Cannot infer local variable type from delegate or lambda expression"

Aw shucks!
Dilip wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 3:12 PM

Patrick Logan spake thusly:
http://patricklogan.blogspot.com/2006/05/expressionism.html
ctodx wrote Lambda is not just a Greek letter
on 05-11-2006 4:34 PM
Sometimes the planets in the heavens align themselves just right and a post you wanted to write is suddenly...
Isaac Gouy wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 9:38 PM
There's a little more about Expression Trees amusement in section 3.5 "Confessions of a Used Programming Language Salesman"
http://www.google.com/url?sa=U&start=1&q=http://research.microsoft.com/~emeijer/Papers/ICFP06.pdf&e=14916
Isaac Gouy wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 9:40 PM
Ooops "Confessions of a Used Programming Language
Salesman"
http://research.microsoft.com/~emeijer/Papers/ICFP06.pdf
Keith J. Farmer wrote re: New drop of C# 3.0/LINQ
on 05-11-2006 11:55 PM
Erik's great -- if you ever get the chance to listen (or watch, more like) him give a talk, do so.
Keith J. Farmer wrote re: New drop of C# 3.0/LINQ
on 05-12-2006 12:08 AM
Re Patrick Logan:

Yes, the expressions can be built programmatically. See the InteractiveQuery sample in the C# Samples folder.

The Expression compilation is to convert the expression from its tree form to real, compiled IL which the CLR can run.



Don Box's Spoutlet wrote Code and Data in C#
on 05-12-2006 3:52 AM
Don Box's Spoutlet wrote Code and Data in C#
on 05-12-2006 3:54 AM
Lazy Coder wrote Welcome to the Age of Expression
on 05-12-2006 6:58 AM
"Expression&lt;Func&lt;int, int&gt;&gt; expr = a =&gt; a + 3;Console.WriteLine(expr); // prints "a =&gt;...
Chris Parker wrote re: New drop of C# 3.0/LINQ
on 05-22-2006 6:41 PM
Wow - that code looks like crap. I have wondered for years what was so appealing about Java and C++, and I see that C# has officially joined the ugly language family.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?