2014-05-19 01:38:32 -04:00
|
|
|
(define-library (picrin control)
|
|
|
|
(import (scheme base))
|
|
|
|
|
2014-05-19 01:45:38 -04:00
|
|
|
; based on paper "Representing Monads" (Filinski 1994)
|
|
|
|
|
2014-05-19 01:38:32 -04:00
|
|
|
(define m #f)
|
|
|
|
|
|
|
|
(define (reset t)
|
|
|
|
(call/cc
|
|
|
|
(lambda (k)
|
|
|
|
(let ((n m))
|
|
|
|
(set! m (lambda (r)
|
|
|
|
(set! m n)
|
|
|
|
(k r)))
|
|
|
|
(t)))))
|
|
|
|
|
|
|
|
(define (shift h)
|
|
|
|
(call/cc
|
|
|
|
(lambda (k)
|
|
|
|
(h (lambda (v)
|
|
|
|
(reset (lambda ()
|
|
|
|
(k v))))))))
|
|
|
|
|
|
|
|
(define prompt reset)
|
|
|
|
(define control shift)
|
|
|
|
|
|
|
|
(export shift
|
|
|
|
reset
|
|
|
|
control
|
|
|
|
prompt))
|