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
4
votes
1 answer

Is call/cc a copy of a stack frame or an actual jump in execution?

I don't understand how the following does not set up an infinite loop: (define call/cc call-with-current-continuation) ; ccc alias (define return #f) ; declare a global variable 'return' (+ 1 (call/cc (lambda (cont) ; setup continuation with 'cont'…
4
votes
1 answer

Implement a return function

I'm trying to implement a return function in Scheme R6RS. I want something such that: (lambda () (do-some-job-before) (return some-value) (do-some-job-after)) executes (do-some-job-before), do not execute (do-some-job-after) and the final…
Aslan986
  • 9,984
  • 11
  • 44
  • 75
3
votes
6 answers

Can any case of using call/cc be rewritten equivalently without using it?

Can any case of using call/cc be rewritten equivalently without using it? For example In (g (call/cc f)), is the purpose of f to evaluate the value of some expression, so that g can be applied to the value? Is (g (call/cc f)) always able to be…
user10082400
3
votes
3 answers

How to implement continuations in dynamic language like JavaScript?

I need some hits how I should go about and implement continuation for lips in JavaScript (my lisp is almost like scheme, except no continuations and TOC). Here is my evaluate function: function getFunctionArgs(rest, { env, dynamic_scope, error }) { …
jcubic
  • 61,973
  • 54
  • 229
  • 402
3
votes
2 answers

How does `values` work in Scheme?

From the R5RS standard: Values might be defined as follows: (define (values . things) (call-with-current-continuation (lambda (cont) (apply cont things)))) My first interpretation of this was that an expression like (+ (values 1 2)) is…
Gradient
  • 2,253
  • 6
  • 25
  • 36
3
votes
1 answer

scheme continuation inside a for-each

I'm currently studying Scheme for a course at my university, while looking at some exercises I got stuck on this particular one. Professor has yet to answer my previous mails therefore I have more chances to receive an answer here faster. Given this…
MaX
  • 489
  • 7
  • 18
3
votes
1 answer

callcc in ruby cause infinite loop?

I'm trying to review the slides of class. The code is supposed to print "early work" once then followed by "later work" twice(you can set the repeat number of the later work). But I wonder why this code doesn't work, and how can I modify the code?…
2ez4rtz
  • 61
  • 4
3
votes
1 answer

How to start captured current continuations in Racket

I am studying call/cc in Racket along the lines of paper Continuations by example: Exceptions, time-traveling search, generators, threads, and coroutines 1. The paper mentions that the most advantageous API is derived from call/cc by providing a…
Marco Faustinelli
  • 3,734
  • 5
  • 30
  • 49
3
votes
1 answer

Does call/cc simulate goto this way?

In the book Lisp in Small Pieces, there is the following example code, which is intended to demo that call/cc could simulate goto. (define (fact n) (let ((r 1) (k 'void)) (call/cc (lambda (c) (set! k c) 'void)) (set! r (* r n)) …
Dong Feng
  • 61
  • 3
3
votes
2 answers

How to interpret callCC in Haskell?

In Scheme executing a continuation obtained from a call/cc effectively jumps back to that initial call/cc and reinstates the saved call stack. I just started learning Haskell and I am trying to figure out how to comprehend callCC. That is try to…
user782220
  • 10,677
  • 21
  • 72
  • 135
3
votes
1 answer

Is it possible to do a call-cc in Go?

Is it possible to do a Call-with-current-continuation in Google's new Language Go?
hawkeye
  • 34,745
  • 30
  • 150
  • 304
2
votes
1 answer

call/cc example in JavaScript

Now that ES6 supports Proper Tail Call, and since according to Wikipedia, "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.", we should be…
2
votes
1 answer

call cc example racket

I'm analyzing this code regarding the use of call/cc. This function is kind of mystical, and it's quite complicated to fully understand. I really cannot understand how this code is working. Below is my interpretation. (define (print+sub x y) …
Walter
  • 123
  • 7
2
votes
2 answers

Is the function argument to `call/cc` written in CPS?

The parameter of call/cc is a procedure taking as its argument a continuation. Is the procedure written in CPS?
user10082400
2
votes
1 answer

Coroutines in Scheme (R5RS)

So I first came across the concept of coroutines in lua and lua's implementation was more or less understandable.. I'm learning scheme now and I understand that the same functionality is implemented with call/cc, but I'm having a bit of trouble…
Chris Bolton
  • 2,878
  • 6
  • 38
  • 57