F-operator

  1. F-operator
  2. Documentation
    1. Shift/Reset - Dynamically scoped shift/reset
      1. %reset
      2. %shift
      3. reset
      4. shift
      5. %reset-values
      6. %shift-values
      7. reset-values
      8. shift-values
    2. BShift/BReset - Statically scoped shift/reset
      1. %breset
      2. %bshift
      3. breset
      4. bshift
      5. %breset-values
      6. %bshift-values
      7. breset-values
      8. bshift-values
    3. Range
      1. range
      2. range
      3. %range
      4. %range
    4. Reflect/Reify - Monads
      1. define-unit
      2. define-bind
      3. reflect
      4. reflect-values
      5. %reflect
      6. reify
      7. reify-values
      8. %reify
    5. GShift/GReset - Generalized shift/reset
      1. greset
      2. gshift
      3. hr-stop
      4. hs-stop
      5. hr-prop
      6. hs-prop
      7. h-compose
      8. h-value
      9. h-datatype?
      10. h-cases
  3. Usage
  4. Examples
  5. Notes
  6. Requirements
  7. Bugs and Limitations
  8. Author
  9. Version history
  10. License

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.

%reset

[syntax] (%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!

%shift

[syntax] (%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>).

reset

[syntax] (reset EXPRESSION ...)

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

shift

[syntax] (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>).

%reset-values

[syntax] (%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!

%shift-values

[syntax] (%shift-values PC-TAG EXPRESSION)

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

reset-values

[syntax] (reset-values EXPRESSION ...)

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

shift-values

[syntax] (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

%breset

[syntax] (%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!

%bshift

[syntax] (%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>).

breset

[syntax] (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 ...).

bshift

[syntax] (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>).

%breset-values

[syntax] (%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!

%bshift-values

[syntax] (%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> ...).

breset-values

[syntax] (breset-values RC-TAG EXPRESSION ...)

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

bshift-values

[syntax] (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)

range

[syntax] (range RC-TAG FROM VALUE STEP TO?)

The value of the delimited continuation RC-TAG 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

range

[syntax] (range RC-TAG FROM [STEP] TO)

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

%range

[syntax] (%range RC-TAG FROM VALUE STEP TO?)

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

%range

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

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

Reflect/Reify - Monads

(require-extension reflect-reify)

define-unit

[syntax] (define-unit KIND BODY ...)

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

define-bind

[syntax] (define-bind KIND BODY ...)

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

reflect

[syntax] (reflect KIND MONAD)

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

reflect-values

[syntax] (reflect-values KIND MONAD)

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

%reflect

[syntax] (%reflect KIND MONAD)

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

reify

[syntax] (reify KIND EXPRESSION)

Return result of EXPRESSION as a monad.

reify-values

[syntax] (reify-values KIND EXPRESSION)

Return result of EXPRESSION as a monad.

%reify

[syntax] (%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

greset

[syntax] (greset HR E)

Reset parameterized by the H Reset procedure HR.

gshift

[syntax] (gshift HS F E)

Shift parameterized by the H Shift procedure HS.

hr-stop

[procedure] (hr-stop V)

H Reset Stop.

hs-stop

[procedure] (hs-stop V)

H Shift Stop

hr-prop

[procedure] (hr-prop V)

H Reset Propagate.

hs-prop

[procedure] (hs-prop V)

H Shift Propagate.

h-compose

[procedure] (h-compose F X)

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

h-value

[procedure] (h-value V)

Returns the value of V as an h-datatype.

h-datatype?

[procedure] (h-datatype? OBJECT)

Is OBJECT an h-datatype?

h-cases

[syntax] (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.

Usage

See individual sections.

Examples

(use shift-reset srfi-41 srfi-45)

(define (my-list->stream list)
  (iteration-procedure->stream
   (lambda (receiver)
     (for-each receiver list))))

(define (iteration-procedure->stream iteration-procedure)
  (reset
    (iteration-procedure
     (lambda (element)
       (shift continue-iteration
         (stream-cons element (lazy (continue-iteration (void)))))))
    stream-null))

Notes

Requirements

datatype miscmacros

Bugs and Limitations

Author

Kon Lovett

Version history

2.0.1
Added miscmacros as a dependency [Ivan Raikov].
2.0.0
Initial Chicken 4 release.

License

Copyright (C) 2009 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.