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

Infinite loop while using call-with-current-continuation in Scheme

I have been reading about call-with-current-continuation particularly in Scheme and have read various articles on many websites. However, I still don't understand how does the control flow work while using call-with-current-continuation. For…
New User
  • 31
  • 3
2
votes
2 answers

call/cc in Python — Possible?

Say, we have the following code in Scheme (define cc #f) (define bar 0) (define (func) (print "This should show only once") (call/cc (lambda (k) (set! cc k))) (print bar) (set! bar (+ bar 1))) (define (g) (func) (print "This should…
2
votes
3 answers

get-first - the-seasoned-schemer

Please take a look at two-in-a-row*? function in chapter 19. My question is about the (leave '()) in the get-first helper function. Note that (waddle l) will either return '() or an atom, which indicates the list has exhausted or an atom from the…
Lin
  • 1,547
  • 2
  • 12
  • 26
2
votes
1 answer

Scheme continuation restarting in weird place

UPDATE: So the issue seems to be with the generator, and not necessarily with the next-token and lookahead functions. I added some display calls around where the set!s were happening, and found that the issue is that after (generate-token) is…
fromClouds
  • 305
  • 2
  • 12
2
votes
2 answers

What is the continuation of call/cc in a let block

I came across a snippet explaining Continuations using call/cc. In the snippet provided below, what is the continuation for the fn called by call/cc is the entire let block, or the lines below the call/cc ? Also can someone provide an explanation on…
draklor40
  • 453
  • 7
  • 17
2
votes
3 answers

Call Continuation CC in Scheme

I'm completly lost with the call continuation in Scheme. Can someone help me with this example ? #lang scheme (define a-continuation '*dummy-value*) (define (myfunction what? l) (cond ((null? l) 0) ((what? (car l)) (+ 1…
Jean
  • 601
  • 1
  • 10
  • 26
2
votes
1 answer

Working with Seaside continuations

How do I get a BlockClosure in Squeak (I want to use BlockClosure>>callCC)? When I write [#foo] that is a BlockContext, what's the deal? Update: I have worked out that BlockClosure is a thing mainly of new compiler. Instead how do I work with…
Marcin
  • 48,559
  • 18
  • 128
  • 201
2
votes
1 answer

The semantic of call/cc and "ensure" in Ruby

As I know so far, Ruby is the only mainstream language that supports both call/cc and try/catch/finally (written as begin/rescue/ensure/end block). I am not familiar with Ruby, but my intuitive tell me that there are potential conflicts of that two,…
Earth Engine
  • 10,048
  • 5
  • 48
  • 78
2
votes
1 answer

Using call/cc to make a loop. let vs begin

Both of the following code blocks should (in my mind) be infinite loops This works (define call/cc call-with-current-continuation) (define l 0) (define i 0) ((lambda () (call/cc (lambda (k) (set! l k))) (write i) (newline) …
timkomip
  • 45
  • 4
2
votes
2 answers

Scheme, call/cc

So for I am trying to figure out this whole call/cc thing in Scheme. Below is the code I am working with: (+ 1 (call/cc (lambda (k) (if (number? k) (call/cc (lambda (k) (k (- 1 k)))) (k 4))))) So here we start adding the two…
user1311286
1
vote
2 answers

why is `(((call/cc (lambda (k) k)) (lambda (x) x)) "HEY!")` evaluated to "HEY!"?

I am reading The scheme programming language and seeing this example in continuation section: (((call/cc (lambda (k) k)) (lambda (x) x)) "HEY!") => "HEY!" I cannot figure out why this expression evaluating to "HEY!" According to the CSE 341 lecture…
1
vote
3 answers

Understanding Implementation of call-with-continuation

I'm trying to understand a scheme procedure written in python code: def callcc(proc): "Call proc with current continuation; escape only" ball = RuntimeWarning("Sorry, can't continue this continuation any longer.") def throw(retval):…
carl.hiass
  • 1,526
  • 1
  • 6
  • 26
1
vote
0 answers

What is the J operator and is it the same as call/cc?

I have heard of the "J operator" or "program point operator", when researching about ISWIM. I would like to know what it is. The Wikipedia article for it is very vague: In computer science, Peter Landin's J operator is a programming construct that…
R Z
  • 422
  • 4
  • 13
1
vote
1 answer

how to analyze the equivalent receiver in call/cc?

I am reading the book Scheme and the Art of Programming, but cannot think of an answer to the following question: If r is (escaper (lambda (continuation) (continuation body)) in (... (call/cc r) ...), when can r be rewritten as (lambda…
Lucas
  • 222
  • 3
  • 9
1
vote
0 answers

Why using goto is regarded as bad practice, but call/cc isn't?

I am currently learning the concept of continuations. I am struggling with understanding why direct control flow manipulation by e.g. goto command is a bad practice, but doing so using call/cc is just fine. Isn't it the same thing, but achieved by…
M. Twarog
  • 2,418
  • 3
  • 21
  • 39