The duplication is because you're evaluating the expression at top
level, so the repl is part of the continuation. The continuation isn't
(lambda (c) (c e2); it's actually something like (lambda (c)
(evaluate-in-repl (c e2)). So when you run (ret 9), you're actually
re-running the repl you had when you evaluated the expression, which
leads to the duplication.
To avoid this, put the expression in a procedure:
#lang racket
(define ret #f)
(define ret2 (lambda (c) (add1 c)))
(define (haha)
(add1
(call/cc
(lambda (k)
(set! ret k) ;; Now ret should be equivalent to ret2.
2))))
Then you get what you expect, because the continuation is delimited by
the procedure definition:
Welcome to DrRacket, version 7.8 [3m].
Language: racket, with debugging; memory limit: 128 MB.
> (haha)
3
> (ret 9)
10
> (ret2 5)
6
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
racket-users...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/CACgrOx%2BnXZpQv_MbDwdAZJSGpMiD%2BE1gB4YH8Rsb_y3%3D6RaAnQ%40mail.gmail.com.