Continuations in Cat

A call-with-current continuation primitive looks like it will be added soon to Cat. The callcc primitive would probably have the following type:

callcc : (’A (’A (’A -> ‘B) -> ‘B) -> ‘B) 

The implementation would call a function after first pushing a pointer to the next instruction on the stack (looks just like a function).

define do_twice { dup [apply] dip apply }

define test { 1 [do_twice] callcc inc }

test  == 3

What do you think? Is there any interest in this feature? It would make translating from a large range of languages such as Scheme or C into Cat much easier. The reason it is needed for C is to make a “return” keyword easier to implement. The translation process wouldn’t have to jump through hoops trying to rewrite the code to make it Cat friendly.

Edit: By the way here are the proposed semantics:

[$A [$B] callcc $C] == [$A [$C] $B]

I have also posted about the idea at http://lambda-the-ultimate.org/node/2281.

Leave a Reply

You must be logged in to post a comment.