Recursive lambda expressions - A world apart from the everday ...

A world apart from the everday ...

Assert.IsTrue(Entries.Count == 0);

Recursive lambda expressions

I feel it very neccessary at this point to warn you that this is most certainly not for the faint hearted ... As the author, Dr T., of the original post says; this might not be practical but it sure is fun. 

"People sometimes complain that you cannot write a lambda expression that is recursive. Good old factorial, for instance, how to write that as a lambda expression? " .... [read more]

believe it or not, but the line below is the single simple lambda function to implement the good old factorial problem;

i => new Func<Func<int,int>,Func<int,int>>(fac => x => x == 0 ? 1 : x * fac(x - 1))(new SelfApplicable<Func<Func<Func<int,int>,Func<int,int>>,Func<int,int>>>(y => f => x => f(y(y)(f))(x))(y => f => x => f(y(y)(f))(x))(fac => x => x == 0 ? 1 : x * fac(x - 1)))(i) 

I'm imagining all sorts of higher job security with this; just think of the possibilities..... Stick out tongue

Ok, my head hurts after that .... need to get more coffee.

Posted: May 24 2007, 07:11 AM by Ryan CrawCour | with 2 comment(s)
Filed under:

Comments

Shaun said:

I wonder what the percentage of programmers understand this at first glance?

# May 24, 2007 1:15 PM

Armand du Plessis said:

<<>@<..<>>>>< I'm surprised my browser didn't crash rendering that...

# May 24, 2007 4:07 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: