[racket] Continuation marks

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Sep 5 20:21:21 EDT 2014

A continuation represents the rest of the computation with respect to a sub-computation, e.g., a procedure call. After a return from a procedure call, anything having to do is gone. 

In Racket, you can grab this continuation, including pieces from sub-sub-computations within the extent of the procedure call. Grabing means you turn them into a value within the language. And on those continuations you can find the marks. By reinstalling these continuations, you can get the marks back. 




On Sep 5, 2014, at 5:24 PM, Gustavo Massaccesi wrote:

> I'm trying to add a continuation mark inside a function, but I want
> that the new mark to be visible after the functions returns. (Mostly
> for curiosity, not an actual problem.)
> 
> I want something like this:
> 
> ;--
> #lang racket/base
> 
> (define (display-cm-x)
>  (displayln
>   (continuation-mark-set->list
>    (current-continuation-marks) 'x)))
> 
> (define (add-cm-x v)
>  '???)
> 
> (define-syntax-rule (with-cm-x v body ...)
>  (with-continuation-mark 'x v
>    body ...))
> 
> (let ()
>  (display-cm-x) ;==>()
>  (with-cm-x 7
>    (display-cm-x)) ;==>(7)
>  (display-cm-x) ;==>()
>  (add-cm-x 7)
>  (display-cm-x) ;actual==>(), expected==>(7)
>  )
> ;--
> 
> The last line prints (), but I wish it prints (7).
> 
> Gustavo
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.