Questions tagged [callcc]

call-with-current-continuation (abbreviated as call/cc) is a control operator in functional programming

The function call-with-current-continuation, commonly abbreviated call/cc, is a control operator in functional programming that originated in the Scheme programming language. It takes a function f as its only argument and applies f to the current continuation (a first-class value represented as a function).

85 questions
157
votes
3 answers

What's the difference between a continuation and a callback?

I've been browsing all over the web in search of enlightenment about continuations, and it's mind boggling how the simplest of explanations can so utterly confound a JavaScript programmer like myself. This is especially true when most articles…
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
65
votes
10 answers

What is call/cc?

I've tried several times to grasp the concept of continuations and call/cc. Every single attempt was a failure. Can somebody please explain me these concepts, ideally with more realistic examples than these on Wikipedia or in other SO posts. I have…
Michał Niedźwiedzki
  • 12,859
  • 7
  • 45
  • 47
34
votes
9 answers

I just don't get continuations!

What are they and what are they good for? I do not have a CS degree and my background is VB6 -> ASP -> ASP.NET/C#. Can anyone explain it in a clear and concise manner?
Oded
  • 489,969
  • 99
  • 883
  • 1,009
34
votes
6 answers

How does the yin-yang puzzle work?

I'm trying to grasp the semantics of call/cc in Scheme, and the Wikipedia page on continuations shows the yin-yang puzzle as an example: (let* ((yin ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c)))) …
Hrundik
  • 1,818
  • 13
  • 13
29
votes
5 answers

call/cc implementation?

I'm trying to find how call/cc is implemented. The best I've found is this Haskell snippet: callCC f = Cont $ \k -> runCont (f (\a -> Cont $ \_ -> k a)) k Although this is not as simple as I want due to the Cont and runCont. I've also found…
Pubby
  • 51,882
  • 13
  • 139
  • 180
22
votes
2 answers

How to make callCC more dynamic?

I thought the right type for ContT should be newtype ContT m a = ContT {runContT :: forall r. (a -> m r) -> m r} and other control operators shift :: Monad m => (forall r. (a -> ContT m r) -> ContT m r) -> ContT m a reset :: Monad m => ContT m a ->…
bobzhang
  • 1,771
  • 3
  • 17
  • 19
22
votes
4 answers

Why doesn't a primitive `call-with-current-continuations` exist in Common Lisp

Scheme offers a primitive call-with-current-continuation, commonly abbreviated call/cc, which has no equivalent in the ANSI Common Lisp specification (although there are some libraries that try to implement them). Does anybody know the reason why…
Paulo Tomé
  • 1,910
  • 3
  • 18
  • 27
21
votes
3 answers

How could the new async feature in c# 5.0 be implemented with call/cc?

I've been following the new announcement regarding the new async feature that will be in c# 5.0. I have a basic understanding of continuation passing style and of the transformation the new c# compiler makes to code like this snippet from Eric…
Gabe Moothart
  • 31,211
  • 14
  • 77
  • 99
21
votes
6 answers

call/cc in Lua - Possible?

The Wikipedia article on Continuation says: "In any language which supports closures, it is possible to write programs in continuation passing style and manually implement call/cc." Either that is true and I need to know how to do it or it is not…
PeterM
  • 1,188
  • 1
  • 10
  • 15
14
votes
2 answers

Can call-with-current-continuation be implemented only with lambdas and closures?

Does anyone know if call/cc can be implemented with just lambdas and closures? It seems that call/cc interrupts the program's flow (like an exception) but lambdas and closures can't do that. Therefore I think call/cc can't be implemented via lambdas…
bodacydo
  • 75,521
  • 93
  • 229
  • 319
11
votes
1 answer

The ContT Monad: Putting the pieces together

Preamble I am trying to wrap my head around how to actually use ContT and callCC for something useful. I'm having trouble following information and control flows around the the code. (but, isn't that the point of a continuation?) There are a lot of…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
10
votes
7 answers

Java: using a RuntimeException to escape from a Visitor

I am being powerfully tempted to use an unchecked exception as a short-circuit control-flow construct in a Java program. I hope somebody here can advise me on a better, cleaner way to handle this problem. The idea is that I want to cut short the…
Chris Conway
  • 55,321
  • 43
  • 129
  • 155
10
votes
1 answer

How come that we can implement call/cc, but the classical logic (intuitionistic + call/cc) is not constructive?

Intuitionistic logic, being constructive, is the basis for type systems in functional programming. The classical logic is not constructive, in particular the law of excluded middle A ∨ ¬A (or its equivalents, such as double negation elimination or…
Petr
  • 62,528
  • 13
  • 153
  • 317
9
votes
3 answers

Is it possible to use call/cc to implement recursion?

I wonder if it is possible to define a recursive function without calling the function itself in its body but somehow using call/cc instead? Thanks.
day
  • 2,292
  • 1
  • 20
  • 23
9
votes
4 answers

call/CC with closures

Wikipedia mentions that "In any language which supports closures and proper tail calls, it is possible to write programs in continuation-passing style and manually implement call/cc." How would one implement this function in for example in…
Masse
  • 4,334
  • 3
  • 30
  • 41
1
2 3 4 5 6