Description

Shift/Reset Control Operators

Author

Kon Lovett

Requires

Download

F-operator.egg

Documentation

The static delimited continuation operators shift and reset.

Shift/Reset - Dynamically scoped shift/reset

(require-extension shift-reset)

A "stuck on control" situation, a 'shift' without an enclosing 'reset', is an error.

macro: (%reset EXPRESSION ...)

Evaluate the body EXPRESSION ... with a delimited continuation. The body will contain one or more instances of (%shift ...).

Any use of (dynamic-wind ...) within the dynamic scope of the partial continuation will be ignored!

macro: (%shift PC-TAG EXPRESSION)

Within the scope of EXPRESSION PC-TAG is bound to the reified partial continuation delimited by the enclosing (%reset ...). Provide a value to the partial continuation using the form (PC-TAG <something>).

macro: (reset EXPRESSION ...)

Evaluate the body EXPRESSION ... with a delimited continuation. The body will contain one or more instances of (shift ...).

macro: (shift PC-TAG EXPRESSION)

Within the scope of EXPRESSION PC-TAG is bound to the reified partial continuation delimited by the enclosing (reset ...). Provide a value to the partial continuation using the form (PC-TAG <something>).

macro: (%reset-values EXPRESSION ...)

Multiple value return version of (%reset ...). The body will contain one or more instances of (%shift-values ...).

Any use of (dynamic-wind ...) within the dynamic scope of the partial continuation will be ignored!

macro: (%shift-values PC-TAG EXPRESSION)

Multiple value return version of (%shift ...). Provide a value to the partial continuation using the form (PC-TAG <something> ...).

macro: (reset-values EXPRESSION ...)

Multiple value return version of (reset ...). The body will contain one or more instances of (shift-values ...).

macro: (shift-values PC-TAG EXPRESSION)

Multiple value return version of (shift ...). Provide a value to the partial continuation using the form (PC-TAG <something> ...).

BShift/BReset - Statically scoped shift/reset

(require-extension bshift-breset)

Invalid delimited continuations, what RC-TAG below represents, and "stuck on control" will generate an error.

macro: (%breset RC-TAG EXPRESSION ...)

Evaluate the body EXPRESSION ... with a delimited continuation named RC-TAG. The body will contain one or more instances of (%bshift RC-TAG ...).

Any use of (dynamic-wind ...) within the dynamic scope of the partial continuation will be ignored!

macro: (%bshift RC-TAG PC-TAG EXPRESSION)

Within the scope of EXPRESSION PC-TAG is bound to the reified partial continuation delimited by the enclosing (%breset RC-TAG ...). Provide a value to the partial continuation using the form (PC-TAG <something>).

macro: (breset RC-TAG EXPRESSION ...)

Evaluate the body EXPRESSION ... with a delimited continuation named RC-TAG. The body will contain one or more instances of (bshift RC-TAG ...).

macro: (bshift RC-TAG PC-TAG EXPRESSION)

Within the scope of EXPRESSION PC-TAG is bound to the reified partial continuation delimited by the enclosing (breset RC-TAG ...). Provide a value to the partial continuation using the form (PC-TAG <something>).

macro: (%breset-values RC-TAG EXPRESSION ...)

Multiple value return version of (%breset ...). The body will contain one or more instances of (%bshift-values RC-TAG ...).

Any use of (dynamic-wind ...) within the dynamic scope of the partial continuation will be ignored!

macro: (%bshift-values RC-TAG PC-TAG EXPRESSION)

Multiple value return version of (%bshift ...). Provide a value to the partial continuation using the form (PC-TAG <something> ...).

macro: (breset-values RC-TAG EXPRESSION ...)

Multiple value return version of (breset ...). The body will contain one or more instances of (bshift-values RC-TAG ...).

macro: (bshift-values RC-TAG PC-TAG EXPRESSION)

Multiple value return version of (bshift ...). Provide a value to the partial continuation using the form (PC-TAG <something> ...).

Range

(require-extension range)
macro: (range RC-TAG FROM VALUE STEP TO?)

The value of the delimited continuation ranges over the set of values specified by the state generation procedure suite. For use with (breset ...).

FROM

Zero argument procedure, returning the initial state.

VALUE

Single argument procedure, of the state, returning the value of the state.

STEP

Single argument procedure, of the state, returning the next state.

TO?

Single argument procedure, of the state, returning #t when the range is complete.

macro: (range RC-TAG FROM [STEP] TO)

The value of the delimited continuation ranges over the number interval [FROM TO], by STEP. The increment is 1 when missing. For use with (breset ...).

macro: (%range RC-TAG FROM VALUE STEP TO?)

Version of (range ...) for use with (%breset ...).

macro: (%range RC-TAG FROM [STEP] TO)

Version of (range ...) for use with (%breset ...).

Reflect/Reify - Monads

(require-extension reflect-reify)
macro: (define-unit KIND BODY ...)

Expands to (define (KIND-unit obj) BODY ...).

macro: (define-bind KIND BODY ...)

Expands to (define (KIND-bind monad func) BODY ...).

macro: (reflect KIND MONAD)

Extract value from MONAD. Plays the role of Haskell '<-'.

macro: (reflect-values KIND MONAD)

Extract value from MONAD. Plays the role of Haskell '<-'.

macro: (%reflect KIND MONAD)

Extract value from MONAD. Plays the role of Haskell '<-'.

macro: (reify KIND EXPRESSION)

Return result of EXPRESSION as a monad.

macro: (reify-values KIND EXPRESSION)

Return result of EXPRESSION as a monad.

macro: (%reify KIND EXPRESSION)

Return result of EXPRESSION as a monad.

GShift/GReset - Generalized shift/reset

(require-extension gshift-greset)

The generalized shift and reset operator family from How to remove a dynamic prompt: static and dynamic delimited continuation operators are equally expressible.

macro: (greset HR E)

Reset parameterized by the H Reset procedure HR.

macro: (gshift HS F E)

Shift parameterized by the H Shift procedure HS.

procedure: (hr-stop V)

H Reset Stop.

procedure: (hs-stop V)

H Shift Stop.

procedure: (hr-prop V)

H Reset Propagate.

procedure: (hs-prop V)

H Shift Propagate.

procedure: (h-compose F X)

Returns the composition of F and X as an h-datatype.

procedure: (h-value V)

Returns the value of V as an h-datatype.

procedure: (h-datatype? OBJECT)

Is OBJECT an h-datatype?

macro: (h-cases E ((F X) ON-h-EXPR) (V ON-V-EXPR))

Deconstructs the h-datatype E, binding F & X for an evaluation of the ON-h-EXPR and V for an evaluation of the ON-V-EXPR.

Issues

Not a direct implementation of partial continuations. Simulated using full continuations.

Examples

;;
;; See "F-operator-test.scm" in the unpacked egg for more examples.
;;

Version

License

Copyright (c) 2006, Kon Lovett.  All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the Software),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Does not supercede any restrictions found in the source code.