#310 Controlflow mechanisms

helium Wed 23 Jul 2008

Many languages have a powerfull controlflow mechanism most wildly known as exception system (well not as powerfull as continuations but still pretty powerful). In some languages you are told that this is only to be used to handle exceptional cases while in other languages people find it perfectly legal to use it for use cases, too.

So let's rename some language constructs:

try   => do
throw => send
catch => receive

And we allow to send arbitrary objects rather than only those with a subtype of sys::Err.

Than we could do something like this:

Bool someFunction()
{
    do {
        someList.each | Int n | {
            if (someCondition)
                send n
        }
    }
    receive (Int n)
        return n
    return 0
}

I know still a litle verbose, but perhaps that's not that bad so people don't overuse this controlflow mechanism.

I anticipate resistance from Java programmers, but hope you'look at it open minded.

jodastephen Wed 23 Jul 2008

One of the good things about Fan is that it is pretty mainstream - understandable to the bulk of Java/C# developers. This idea moves away from that. Its also easily achievable with Err:

Bool someFunction() {
  try {
    someList.each | Int n | {
      if (someCondition) {
        throw Err {value = n}
      }
    }
    return 0
  } catch (Err err) {
    return err.value
  }
}

brian Wed 23 Jul 2008

Cool idea, although I think this really gets into how to use closures to build control structures (and non-local returns, etc). I'm not sure I want to go there for 1.0.

Login or Signup to reply.