Just sharing some of my inconsequential lunch conversations with you... RSS  

Saturday, December 22, 2007

Continuations

Ok, continuations is not the way we from the imperative world are use to think. Yet Another Language Geek defines it like this:

CPS (Continuation-Passing Style) turns a program inside-out. In the process, the programmer may feel that his brain has been turned inside-out as well.

He carries on defining some simple samples. Here's his factorial sample:

     static void fact(int n, Action<int> action)
{
if (n == 0)
{
action(1);
}
else
{
fact(n - 1, x => action(n * x));
}
}

static void Main(string[] args)
{
fact(5, x => Console.WriteLine(x));
}

Please follow the rest of the his post - it's loaded with samples usable on the real world.

No comments:

Development Catharsis :: Copyright 2006 Mário Romano