[racket] Behavior of continuation-mark-set->list and continuation-mark-set-first with respect to key values

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun May 6 09:56:38 EDT 2012

continuation-mark-set->list always does return all of the bindings,
but continuation marks are carefully designed to avoid breaking tail
recursion (they let you understand the tail behavior of your program,
more accurately) so that's why you see only one binding.

continuation-mark-set-first can be more efficient than
continuation-mark-set->list and it is more likely to work in futures.
That's the only reason it exists.

Robby

On Sat, May 5, 2012 at 11:02 PM, Galler <lzgaller at optonline.net> wrote:
> BACKGROUND:
>
> Per the documentation:
>
> with-continuation-mark  causes a key to be associated with a binding within
> a continuation frame
>
> continuation-mark-set->list returns the binding(s) associated with that
> particular key, for any given continuation-mark-set
>
> while
>
> continuation-mark-set-first returns the first (innermost) binding associated
> with a particular key
>
> QUESTIONABLE  BEHAVIOR
>
> The issue is:
>
> if a key is reused, the only binding continuation-mark-set->list returns is
> the innermost binding.
>
> So continuation-mark-set->list could only possibly return **one** value
>
> and
>
> continuation-mark-set-first  appears redundant
>
> Is that the desired behavior? I would have expected
> continuation-mark-set->list to return all the bindings for a particular key.
>
> Additionally, I suspect continuation-mark-set->context has to be implemented
> using the 'return a list of all bindings for a single key' behavior, since
> the documentation indicates it uses a single private key.
>
>
> EXAMPLE
>
> #lang racket
> (with-continuation-mark 'global  'outermost-value
>  (let/cc k-outer
>    (with-continuation-mark 'global 'middle-value
>      (let/cc k-inner
>        (with-continuation-mark 'global 'inner-value (begin
>                                                       (display
> (continuation-mark-set->list (current-continuation-marks) 'global))
>                                                       (newline)
>                                                       (display
> (continuation-mark-set->list (continuation-marks k-inner) 'global))
>                                                       (newline)
>                                                       (display
> (continuation-mark-set->list (continuation-marks k-outer) 'global))
>         ))))))
>
> ;Returns
>
> ;(inner-value)
>
> ;(middle-value)
>
> ;(outermost-value)
>
> but I would have expected:
>
> ;Returns
>
> ;(inner-value) (middle-value) (outermost-value)
>
> ;(middle-value) (outermost-value)
>
> ;(outermost-value)
>
>
> Thanks very much for looking at this.
>
> R/
>
> Zack
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users


Posted on the users mailing list.