PasteRack.org
Paste # 27844
2020-03-13 12:11:28

Fork as a new paste.

Paste viewed 568 times.


Embed:

continuations in plait

#lang plait

(define checkpoint-param (make-parameter (lambda () (error 'checkpoint! "outside with-checkpoint"))))
(define (checkpoint!) ((parameter-ref checkpoint-param)))

(define with-checkpoint
  (let* ([last-checkpoint (none)])
    (lambda (thunk)
      (lambda ()
        (parameterize ([checkpoint-param
                        (lambda ()
                          (let/cc k
                            (set! last-checkpoint (some k))))])
          (type-case (Optionof (Void -> 'a)) last-checkpoint
            [(none) (thunk)]
            [(some k) (k (void))]))))))
      
(define printer
  (with-checkpoint
    (lambda ()
      (begin
        (display "first\n")
        (checkpoint!)
        (display "second\n")))))


(printer)
(printer)