PasteRack.org
Paste # 94811
2020-03-13 12:10:56

Fork as a new paste.

Paste viewed 276 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)

=>

standard-module-name-resolver: collection not found
  for module path: plait/lang/reader
  collection: "plait/lang"
  in collection directories:
   /home/pasterack/.racket/7.3/collects
   /home/pasterack/racket73/collects
   ... [166 additional linked and package directories]
  context...:
   show-collection-err
   standard-module-name-resolver
   do-dynamic-require5
   read-syntax3
   /home/pasterack/racket73/share/pkgs/scribble-lib/scribble/private/manual-code.rkt:112:0: get-tokens
   /home/pasterack/racket73/share/pkgs/scribble-lib/scribble/private/manual-code.rkt:56:0: typeset-code15
   "/home/pasterack/pasterack/tmp/94811/94811code.scrbl": [running body]
   temp37_0
   for-loop
   run-module-instance!125
   do-dynamic-require5
   loop
   ...cket/cmdline.rkt:191:51
   "/home/pasterack/racket73/share/pkgs/scribble-lib/scribble/run.rkt": [running body]
   temp37_0
   for-loop
   ...