chickadee » F-operator

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

F-operator

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

(reset EXPRESSION ...)syntax

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

shift

(shift PC-TAG EXPRESSION)syntax

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

(reset-values EXPRESSION ...)syntax

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

shift-values

(shift-values PC-TAG EXPRESSION)syntax

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

(breset RC-TAG EXPRESSION ...)syntax

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

bshift

(bshift RC-TAG PC-TAG EXPRESSION)syntax

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

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

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

bshift-values

(bshift-values RC-TAG PC-TAG EXPRESSION)syntax

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

Range

(require-extension range)

range

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

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

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

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 ...).

Reflect/Reify - Monads

(require-extension reflect-reify)

The Monad example from Filinski, POPL '94

define-unit

(define-unit KIND BODY ...)syntax

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

define-bind

(define-bind KIND BODY ...)syntax

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

reflect

(reflect KIND MONAD)syntax

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

reflect-values

(reflect-values KIND MONAD)syntax

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

reify

(reify KIND EXPRESSION)syntax

Return result of EXPRESSION as a monad.

reify-values

(reify-values KIND EXPRESSION)syntax

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

(greset HR E)syntax

Reset parameterized by the H Reset procedure HR.

gshift

(gshift HS F E)syntax

Shift parameterized by the H Shift procedure HS.

hr-stop

hr-stop Vprocedure

H Reset Stop.

hs-stop

hs-stop Vprocedure

H Shift Stop

hr-prop

hr-prop Vprocedure

H Reset Propagate.

hs-prop

hs-prop Vprocedure

H Shift Propagate.

h-compose

h-compose F Xprocedure

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

h-value

h-value Vprocedure

Returns the value of V as an h-datatype.

h-datatype?

h-datatype? OBJECTprocedure

Is OBJECT an h-datatype?

h-cases

(h-cases E ((F X) ON-h-EXPR) (V ON-V-EXPR))syntax

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

3.0.0
Remove %reset, %shift, %reset-values, %shift-values, %breset, %bshift, %breset-values, %bshift-values, %range, %reflect, & %reify.
2.0.4
Has argc-checks.
2.0.3
Use er-macro-transformer.
2.0.2
Has lambda-info.
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.

Contents »