Questions tagged [continuation]

11 questions
22
votes
3 answers

Which are the alternatives to using a stack to represent function call semantics?

We all know and love that function calls are usually implemented using the stack; there are frames, return addresses, parameters, the whole lot. However, the stack is an implementation detail: calling conventions may do different things (i.e. x86…
20
votes
2 answers

Y combinator and tail call optimizations

The definition of a Y combinator in F# is let rec y f x = f (y f) x f expects to have as a first argument some continuation for the recursive subproblems. Using the y f as a continuation, we see that f will be applied to successive calls as we can…
nicolas
  • 349
  • 1
  • 7
17
votes
4 answers

What is an example of a continuation not implemented as a procedure?

An interesting discussion about the distinction between callbacks and continuations over on SO has prompted this question. By definition, a continuation is an abstract representation of the logic needed to complete a computation. In most languages…
13
votes
7 answers

Best practice to "continue" from inside a nested loop?

Here is a simplified sample. Basically, it does checks on a string from a string list. If the check passes, it will remove that string (filterStringOut(i);), and it is no longer necessary to continue any other checks. Thus continue…
Anon
  • 3,565
  • 3
  • 27
  • 45
12
votes
3 answers

Are first-class continuations useful in modern object-oriented programming languages?

Continuations are extremely useful in functional programming languages (e.g. the Cont monad in Haskell) because they allow a simple and regular notation for imperative-style code. They're also useful in some older imperative languages because they…
Jules
  • 17,614
  • 2
  • 33
  • 63
11
votes
4 answers

How do you keep code with continuations/callbacks readable?

Summary: Are there some well-established best-practice patterns that I can follow to keep my code readable in spite of using asynchronous code and callbacks? I'm using a JavaScript library that does a lot of stuff asynchronously and heavily relies…
Heinzi
  • 9,646
  • 3
  • 46
  • 59
4
votes
1 answer

What's the relation between Promises and Continuations

I think I understand what Promises are about, and I think I understand what continuations are about, but I still fail to see what their connection is. In what ways do Promises use Continuations. They never return, which is explained by the fact that…
hgiesel
  • 771
  • 1
  • 7
  • 12
4
votes
1 answer

How is one expected to use open sockets with [delimited] continuations?

I'm trying to figure out how an open socket or file handle should interact with continuations. Searching has revealed that dynamic-wind is probably part of the solution, but I'm more interested in the methodology rather than the implementation, and…
John Cartwright
  • 333
  • 2
  • 10
4
votes
3 answers

Can't understand example using continuations

I'm reading the r6rs Scheme report and am confused by the explanation of continuations (I find it to be too dense and lacking of examples for a beginner). What is this code doing and how does it evaluate to 4? Why does call/cc want an argument…
user39685
1
vote
1 answer

Continuations, coroutines, and tail-call optimization

I am trying to learn continuations and use them to implement coroutines in Scheme. I have two procedures (coroutines) a and b, and I switch between them in the following way: ;; c is a continuation. (define (a c) ... ;; Switch to the other…
Giorgio
  • 19,486
  • 16
  • 84
  • 135
0
votes
1 answer

Simple tic-tac-toe GUI in Common Lisp: Avoid using Continuation Passing Style?

I've made a simple Tic-Tac-Toe game in Common Lisp using the Ltk library. One of the things I wanted to do was to support CPU vs CPU, human vs human, human vs CPU, and CPU vs human. Also, possibly multiple types of CPU algorithms. The ideal way to…
wlad
  • 101
  • 3