The Icon Programming Language
The threads on closures and continuations for Java reminds me of my erstwhile favorite language: Icon.
Icon is an Algol-family language with a twist. Functions and expressions can do much more than just return values: they can “fail”, “suspend” values, and return values. “Suspended” function calls/expressions can be resumed where they suspended so that they can try again. Resumption is driven by downstream failure.
Under the hood the Icon compiler used CPS conversion and closures of dynamic extent (meaning: allocated on the stack, not on the heap) to implement continuations of dynamic extent (meaning: you could call a continuation only once and only while it remains in dynamic scope). Resumption was just a matter of calling the nearest suspended expression’s continuation instead of the current continuation, whereas suspending and returning both involve calling the current continuation.
All of this makes Icon natural for implementing depth-first backtracking search algorithms.
If you wanted breadth-first backtracking, you could always use “co-expressions” (a form of co-routine adapted to Icon concepts), but it was a bit artificial. If you really wanted breadth-first backtracking you’d have to use continuations of indefinite extent under the hood.
I can’t do Icon justice with some examples — it’s been too long since I’ve used it, but its website has lots of references and tutorials, and the main book about Icon is available in PDF.
Incidentally, there’s an Icon-in-Java implementation: Jcon :)
Hi Nico. Please fix the link to Icon website (http://www.cs.arizona.edu/icon/) … currently it’s pointing to this very post.
Cheers,
Tomas
Tomas said this on September 11, 2006 at 02:54 |
Oops. That was a typo in my html that roller, er, helpfully, “fixed.”
Nico said this on September 11, 2006 at 09:12 |