tag:blogger.com,1999:blog-8263949408347549596.post8984543227038509649..comments2023-10-23T23:19:01.111+02:00Comments on Object-Oriented Software Development: C# Puzzle No.16 (advanced)Wiktor Zychlahttp://www.blogger.com/profile/04420514974154487039noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8263949408347549596.post-88711926763683255962009-05-27T15:55:52.367+02:002009-05-27T15:55:52.367+02:00Thanks! That's kind of a hard term to google effe...Thanks! That's kind of a hard term to google effectively.Mojohttps://www.blogger.com/profile/09353259075625848908noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-78270706805519637212009-05-27T15:48:43.241+02:002009-05-27T15:48:43.241+02:00http://blogs.msdn.com/wesdyer/archive/2007/02/02/a...http://blogs.msdn.com/wesdyer/archive/2007/02/02/anonymous-recursion-in-c.aspx<br /><br />http://www.dreamsongs.com/NewFiles/WhyOfY.pdf<br /><br />http://blogs.msdn.com/madst/archive/2007/05/11/recursive-lambda-expressions.aspxWiktor Zychlahttps://www.blogger.com/profile/04420514974154487039noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-70641172907680002112009-05-27T15:24:02.273+02:002009-05-27T15:24:02.273+02:00Who the what now? Where can I find more informati...Who the what now? Where can I find more information about this wacky Y operator?Mojohttps://www.blogger.com/profile/09353259075625848908noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-53297857189679933052009-05-27T13:59:21.827+02:002009-05-27T13:59:21.827+02:00That's exactly the solution I've been thinking of....That's exactly the solution I've been thinking of. I think it's surprisingly ellegant.<br /><br />Nonetheless, Deto's solution was indeed very creative.Wiktor Zychlahttps://www.blogger.com/profile/04420514974154487039noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-11455940070912798312009-05-27T10:26:46.032+02:002009-05-27T10:26:46.032+02:00I use google and that's the product: (but I...I use google and that's the product: (but I'm not sure)<br /><br />static void Main(string[] args)<br />{<br /> List<int> list = new List<int>() { 1,2,3,4,5 };<br /><br /> foreach (var item in list.Select(Y<int,int>(f => i => i <= 1 ? 1 : f(i-1))))<br /> Console.WriteLine(item);<br />}<br /><br />delegate Func<A, R> Recursive<A, R>(Recursive<A, R> r);<br /><br />static Func<A, R> Y<A, R>(Func<Func<A, R>, Func<A, R>> f)<br />{<br /> Recursive<A, R> rec = r => a => f(r(r))(a);<br /> return rec(rec);<br />}Unknownhttps://www.blogger.com/profile/10628108764601706781noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-8388184709669754362009-05-26T22:37:05.526+02:002009-05-26T22:37:05.526+02:00what a great solution :) I would never think of an...what a great solution :) I would never think of anything like that.<br /><br />can you do it without reflection?<br /><br />hint: <br /><br />you should dig around fixed point operator of lambda expressions, known as the "Y operator". Derived by Curry/Turing, the Y operator is used to define recursion in pure lambda calculus. What's less obvious - the Y operator can be defined and used in C#.Wiktor Zychlahttps://www.blogger.com/profile/04420514974154487039noreply@blogger.comtag:blogger.com,1999:blog-8263949408347549596.post-56538209040106196732009-05-26T18:30:17.868+02:002009-05-26T18:30:17.868+02:00I'm very creative :))
List<int> list =...I'm very creative :))<br /><br /><br />List<int> list = new List<int>() { 1,2,3,4,5 };<br /> foreach (var item in list.Select( i => {<br /> if(i<=1)<br /> return 1;<br /> StackTrace callStack = new StackTrace();<br /> StackFrame frame = callStack.GetFrame(0);<br /> MethodBase method = frame.GetMethod();<br /><br /> return (int)method.Invoke(null,new object[]{ i-1});<br /><br /> }) ) {<br /> Console.WriteLine( item );<br /> }Detohttp://www.hakger.xorg.plnoreply@blogger.com