[racket] Continuation marks

From: Gustavo Massaccesi (gustavo at oma.org.ar)
Date: Sat Sep 6 10:36:37 EDT 2014

I agree that to get this output, using continuation marks is a bad
idea. It'd be much better to use a parameter (or set!ing a global
variable at a last resort).

I'm trying to understand continuations marks. I'm reading some parts
of the Racket compiler, and internally the functions have some flags
that are not visible from the Racket code.

One of the flags is 'preserves-marks. From
http://docs.racket-lang.org/raco/decompile.html

> The preserves-marks? field is true if calling the function is expected to leave continuation marks unchanged by the time it returns.

So: Can a function change the continuation marks after it returns?
What does that exactly mean? Can I use that to complete the code in my
original e-mail? Is that a good idea for a real program?

(The last question is easy: No. :) )


I also read the answer from Matthias Felleisen. I'm not sure that I
understood it completely, but somehow it give me a new idea to solve
this. But I need to try it before I'm sure it works.


Gustavo

On Fri, Sep 5, 2014 at 7:04 PM, John Clements <clements at brinckerhoff.org> wrote:
>
> On Sep 5, 2014, at 2:24 PM, Gustavo Massaccesi <gustavo at oma.org.ar> 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).
>
> This is going to sound flip, but … it sounds like you don’t want continuation marks. The whole point of continuation marks is that they’re associated with continuations, and will disappear when those continuations are gone.
>
> The example you give isn’t quite enough to figure out exactly what you want; it sounds like some combination of fluid-let and … something else.
>
> Maybe you can describe why it is that you want this behavior?
>
> John
>


Posted on the users mailing list.