Tim, if you paste your code in the definitions in DrRacket (with the #lang
racket line), and run it (as a module, thus), you obtain this in the
interactions window:
3
10
6

The `3` is because of the `(add1 (call/cc ... 2)))` expression, which is
reduced to `(add1 2)` with the side effect of recording the continuation in
`ret`.
The `10` corresponds to `(ret 9)`.


On Tue, Dec 8, 2020 at 2:26 AM Tim Meehan <[email protected]> wrote:

> I've read a lot about call/cc, and each time wind up just moving on. So
> this is an early New Year's resolution: getting a better understanding of
> it.
>
> According to Wikipedia's page on continuations, the continuation of the
> statement:
>
> ((call/cc f) e2)
>
> is:
>
> (lambda (c) (c e2))
>
> #lang racket
> (define ret #f)
> (define ret2 (lambda (c) (add1 c)))
>
> (add1
>  (call/cc
>   (lambda (k)
>     (set! ret k) ;; Now ret should be equivalent to ret2.
>     2)))
>
> (ret 9) ;; Why does this print twice?
> (ret2 5) ;; This only prints once, like I would have expected.
>
> --
> 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 [email protected].
> 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
> <https://groups.google.com/d/msgid/racket-users/CACgrOx%2BnXZpQv_MbDwdAZJSGpMiD%2BE1gB4YH8Rsb_y3%3D6RaAnQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABNTSaG1R9eM%3DSRjbmWcBKFMyzBTou7O%3D2_0jgDg2_2qSuLb%3Dg%40mail.gmail.com.

Reply via email to