# Why does this continuation return twice?

**URL:** <https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138>\
**Category:** Questions & Answers\
**Created:** [March 9, 2026, 8:11pm UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138 "2026-03-09T20:11:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nealburns5](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@nealburns5](https://racket.discourse.group/u/nealburns5)\
**Post date:** [March 9, 2026, 8:11pm UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138/1 "2026-03-09T20:11:59Z")

</div>

Why do I get 2 return values when I run this from the repl?

```scheme
#lang racket
(require db racket/pretty racket/control)

(define (make-query-func db-path)
   
  (define conn (sqlite3-connect #:database db-path
                                #:mode 'create))
   
  (define sql (get-query))
                             
  (with-handlers ([exn:fail:sql? (lambda (e) (printf "Got exception: ~S~n" e))])
    (let ((result (query-rows conn sql)))
      result)))

(define send-query #f)

(define (get-query)
  (call/comp
   (λ (return-cont)
     (set! send-query return-cont)
     (abort/cc this-prompt (λ () #f)))))

(define this-prompt
  (make-continuation-prompt-tag 'this-prompt))

(call-with-continuation-prompt
 (λ ()
   (make-query-func "this-db.db"))
 this-prompt)

```

Running:

```scheme
Welcome to DrRacket, version 9.1 [cs].
Language: racket, with debugging; memory limit: 2048 MB.
#f
> (send-query "SELECT * FROM Foo ORDER BY Col1 DESC")
'(#("one" "two" "three") #("four" "five" "six"))
'(#("one" "two" "three") #("four" "five" "six"))
> (send-query "SELECT COUNT(*) FROM Foo")
'(#(2))
'(#(2))
> 

```

Thanks in advance.  
Neal

---

<div class="post-metadata">

**Author:** ![ryanc](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/ryanc/32/71_2.png) [@ryanc](https://racket.discourse.group/u/ryanc)\
**Post date:** [March 9, 2026, 9:38pm UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138/2 "2026-03-09T21:38:12Z")

</div>

When you capture the continuation with `(call/comp (λ (return-cont) ....))`, you don't delimit it with `this-prompt`, so the continuation you get looks like this:

```
(print-result
  (prompt
    (let ([sql []])
      (query-rows conn sql))
    this-prompt)))])

```

(I've turned the `(define sql ....)` into a `let` and simplified away some other distractions.)

The `print-result` is inserted by the `racket` language's `#%module-begin` macro. That's why expressions in the module body get printed out. The `print-result` form is actually a macro, but for now you can think of it like a procedure that just prints the given value (if not void) _and returns it_.

(Arguably, the call to `print-result` should be outside the default module-body prompt, not inside it. Or rather, since the existing prompt is installed by a lower level, maybe `print-result` should install its own prompt.)

When you apply the continuation, it performs the query, and then the captured call to `print-result` prints the result. Then it returns the result to the REPL, which prints it again.

---

<div class="post-metadata">

**Author:** ![nealburns5](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@nealburns5](https://racket.discourse.group/u/nealburns5)\
**Post date:** [March 9, 2026, 11:10pm UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138/3 "2026-03-09T23:10:18Z")

</div>

```scheme
#lang racket
(require db racket/pretty racket/control)

(define (make-query-func db-path)
   
  (define conn (sqlite3-connect #:database db-path
                                #:mode 'create))
   
  (define sql (get-query))
                             
  (with-handlers ([exn:fail:sql? (lambda (e) (printf "Got exception: ~S~n" e))])
    (let ((result (query-rows conn sql)))
      result)))

(define send-query #f)

(define (get-query)
  (call/comp
   (λ (return-cont)
     (set! send-query return-cont)
     (abort/cc this-prompt (λ () #f))) this-prompt))

(define this-prompt
  (make-continuation-prompt-tag 'this-prompt))

(call-with-continuation-prompt
 (λ ()
   (make-query-func "this-db.db"))
 this-prompt)

```

I'm going to think about the sequence of events that you described, but I supplied `this-prompt` as the second argument to `call/comp` and that solved the double return. Is there anything else that you see wrong, before I close the book on this?

Thanks a bunch,  
Neal

---

<div class="post-metadata">

**Author:** ![nealburns5](https://avatars.discourse-cdn.com/v4/letter/n/35a633/32.png) [@nealburns5](https://racket.discourse.group/u/nealburns5)\
**Post date:** [March 10, 2026, 1:55am UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138/4 "2026-03-10T01:55:27Z")

</div>

Just to be clear, this use case requires passing the prompt tag to 3 functions: `call/comp`, `abort/cc` and `call-with-continuation-prompt`? Or am I doing something redundant?

---

<div class="post-metadata">

**Author:** ![ryanc](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/ryanc/32/71_2.png) [@ryanc](https://racket.discourse.group/u/ryanc)\
**Post date:** [March 10, 2026, 1:54pm UTC](https://racket.discourse.group/t/why-does-this-continuation-return-twice/4138/5 "2026-03-10T13:54:49Z")

</div>

Right, all three need the same prompt tag.
