1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
continuation-marks
current-continuation-marks
continuation-mark-set->list
continuation-mark-set->list*
continuation-mark-set-first
continuation-mark-set?
continuation-mark-set->context
Version: 4.0.2

 

9.5 Continuation Marks

See Continuation Frames and Marks and Prompts, Delimited Continuations, and Barriers for general information about continuation marks.

The list of continuation marks for a key k and a continuation C that extends C0 is defined as follows:

The with-continuation-mark form installs a mark on the first frame of the current continuation (see Continuation Marks: with-continuation-mark). Procedures such as current-continuation-marks allow inspection of marks.

Whenever Scheme creates an exception record for a primitive exception, it fills the continuation-marks field with the value of (current-continuation-marks), thus providing a snapshot of the continuation marks at the time of the exception.

When a continuation procedure returned by call-with-current-continuation or call-with-composable-continuation is invoked, it restores the captured continuation, and also restores the marks in the continuation’s frames to the marks that were present when call-with-current-continuation or call-with-composable-continuation was invoked.

(continuation-marks cont [prompt-tag])  continuation-mark-set?

  cont : continuation?

  prompt-tag : prompt-tag? = (default-continuation-prompt-tag)

Returns an opaque value containing the set of continuation marks for all keys in the continuation cont up to the prompt tagged by prompt-tag. If cont is an escape continuation (see Prompts, Delimited Continuations, and Barriers), then the current continuation must extend cont, or the exn:fail:contract exception is raised. If cont was not captured with respect to prompt-tag and does not include a prompt for prompt-tag, the exn:fail:contract exception is raised.

(current-continuation-marks [prompt-tag])

  continuation-mark-set?

  prompt-tag : prompt-tag? = (default-continuation-prompt-tag)

Returns an opaque value containing the set of continuation marks for all keys in the current continuation up to prompt-tag. In other words, it produces the same value as

  (call-with-current-continuation

    (lambda (k)

      (continuation-marks k prompt-tag))

    prompt-tag)

(continuation-mark-set->list

 

mark-set

 

 

 

 

 

 

key-v

 

 

 

 

 

 [

prompt-tag])

 

 

list?

  mark-set : continuation-mark-set?

  key-v : any/c

  prompt-tag : prompt-tag? = (default-continuation-prompt-tag)

Returns a newly-created list containing the marks for key-v in mark-set, which is a set of marks returned by current-continuation-marks. The result list is truncated at the first point, if any, where continuation frames were originally separated by a prompt tagged with prompt-tag..

(continuation-mark-set->list*

 

mark-set

 

 

 

 

 

 

key-v

 

 

 

 

 

 [

none-v

 

 

 

 

 

 

prompt-tag])

 

 

(listof vector?)

  mark-set : continuation-mark-set?

  key-v : any/c

  none-v : any/c = #f

  prompt-tag : prompt-tag? = (default-continuation-prompt-tag)

Returns a newly-created list containing vectors of marks in mark-set for the keys in key-list, up to prompt-tag. The length of each vector in the result list is the same as the length of key-list, and a value in a particular vector position is the value for the corresponding key in key-list. Values for multiple keys appear in a single vector only when the marks are for the same continuation frame in mark-set. The none-v argument is used for vector elements to indicate the lack of a value.

(continuation-mark-set-first

 

mark-set

 

 

 

 

 

 

key-v

 

 

 

 

 

 [

prompt-tag])

 

 

any

  mark-set : (or/c continuation-mark-set? false/c)

  key-v : any/c

  prompt-tag : prompt-tag? = (default-continuation-prompt-tag)

Returns the first element of the list that would be returned by (continuation-mark-set->list (or mark-set (current-continuation-marks prompt-tag)) key-v prompt-tag), or #f if the result would be the empty list. Typically, this result can be computed more quickly using continuation-mark-set-first.

(continuation-mark-set? v)  boolean?

  v : any/c

Returns #t if v is a mark set created by continuation-marks or current-continuation-marks, #f otherwise.

(continuation-mark-set->context mark-set)  list?

  mark-set : continuation-mark-set?

Returns a list representing an approximate “stack trace” for mark-set’s continuation. The list contains pairs, where the car of each pair contains either #f or a symbol for a procedure name, and the cdr of each pair contains either #f or a srcloc value for the procedure’s source location (see Counting Positions, Lines, and Columns); the car and cdr are never both #f.

Conceptually, the stack-trace list is the result of continuation-mark-set->list with mark-set and Scheme’s private key for procedure-call marks. The implementation may be different, however, and the results may merely approximate the correct answer. Thus, while the result may contain useful hints to humans about the context of an expression, it is not reliable enough for programmatic use.

A stack trace is extracted from an exception and displayed by the default error display handler (see current-error-display-handler) for exceptions other than exn:fail:user (see raise-user-error in Raising Exceptions).

Examples:

  > (define (extract-current-continuation-marks key)

       (continuation-mark-set->list

        (current-continuation-marks)

        key))

  > (with-continuation-mark 'key 'mark

      (extract-current-continuation-marks 'key))

  (mark)

  > (with-continuation-mark 'key1 'mark1

      (with-continuation-mark 'key2 'mark2

        (list

         (extract-current-continuation-marks 'key1)

         (extract-current-continuation-marks 'key2))))

  ((mark1) (mark2))

  > (with-continuation-mark 'key 'mark1

      (with-continuation-mark 'key 'mark2 ; replaces previous mark

        (extract-current-continuation-marks 'key)))

  (mark2)

  > (with-continuation-mark 'key 'mark1

      (list ; continuation extended to evaluate the argument

       (with-continuation-mark 'key 'mark2

          (extract-current-continuation-marks 'key))))

  ((mark2 mark1))

  > (let loop ([n 1000])

      (if (zero? n)

          (extract-current-continuation-marks 'key)

          (with-continuation-mark 'key n

            (loop (sub1 n)))))

  (1)