News for hackers. Stuff that matters.
Re:Poll: What's Your Favorite Programming Language? by MatthewPhillips on Friday March 23, 2012 @05:37PM (#3747452)
Can't recursively call a lambda function, no thanks.
Re:Poll: What's Your Favorite Programming Language? by chrisb on Friday March 23, 2012 @06:25PM (#3747675)
There are two ways of recursively calling lambda functions, neither perfect, but both usable.

  Func<int,int> fib = null;
  fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;
Or write yourself a Y fixed-point combinator, described in http://blogs.msdn.com/b/wesdyer/archive/2007/02/02/anonymous...

  delegate Func<A,R> Recursive<A,R>(Recursive<A,R> r);
  static Func<A, R> Y<A, R>(Func<Func<A, R>, Func<A, R>> f) {
    Recursive<A, R> rec = r => a => f(r(r))(a);
    return rec(rec);
  }
used like this:

  Func<int,int> fib = Y<int,int>(f => n => n > 1 ? f(n - 1) + f(n - 2) : n);
(I'm not advocating writing a fib function this way, but it's a useful example!)
Re:Poll: What's Your Favorite Programming Language? by icebraining on Friday March 23, 2012 @06:22PM (#3747653)