ControlFeaturesAPI - leftmike/foment GitHub Wiki

(import (foment base)) to use these procedures.

Continuations

procedure: (call-with-continuation-prompt proc prompt-tag handler arg ...)

Mark the current continuation with prompt-tag and apply proc to arg ....

Within the dynamic extent of proc if abort-current-continuation is called with prompt-tag then the continuation is reset to the closest prompt-tag mark, handler is applied to the val ... passed to abort-current-continuation. And the result of call-with-continuation-prompt is the result of handler.

Otherwise, proc returns normally and the result of call-with-continuation-prompt is the result of proc.

If prompt-tag is the default prompt tag, then handler must be default-prompt-handler.

procedure: (abort-current-continuation prompt-tag val ...)

Reset the continuation to the nearest prompt-tag mark. Apply handler (from call-with-continuation-prompt) to the val ....

If aborting to the default prompt tag, pass a thunk as the val ....

procedure: (default-prompt-tag)
procedure: (default-continuation-prompt-tag)

Return the default prompt tag. The start of the continuation for every thread has a mark for the default prompt tag.

procedure: default-prompt-handler

default-prompt-handler reinstalls the mark for the default prompt tag and calls the thunk.

(define (default-prompt-handler proc)
    (call-with-continuation-prompt proc (default-prompt-tag) default-prompt-handler))

Continuation Marks

A continuation mark consists of a key and a value.

syntax: (with-continuation-mark key val expr)

The front of the continuation is marked with key and val. If the front of the continuation already contains a mark with key then it is updated to have val as its value. Otherwise, a new mark is added for key and val. If the front of the continuation already has any marks, irrespective of what keys those marks contain, then expr is called in the tail position.

(with-continuation-mark 'key 1
    (with-continuation-mark 'key 2
        (with-continuation-mark 'key 3
            (continuation-mark-set->list (current-continuation-marks) 'key))))
=> 3

(define (count n m)
    (if (= n m)
        (continuation-mark-set->list (current-continuation-marks) 'key)
        (let ((r (with-continuation-mark 'key n (count (+ n 1) m))))
            r)))
(count 0 4) => (3 2 1 0)

See SRFI 157: Continuation marks for the procedures related to continuation marks.

Notify and Control-C

procedure: (with-notify-handler handler thunk)

Execute thunk. If any notifications happen in the dynamic extent of thunk then handler will be called.

procedure: (set-ctrl-c-notify! disposition)

disposition must be exit, ignore, or broadcast. If disposition is exit, then the program will exit when ctrl-c is pressed. If disposition is ignore, then ctrl-c will be ignored. If disposition is broadcast, then call every notify handler for every thread with sigint as the argument.

⚠️ **GitHub.com Fallback** ⚠️