[racket] Macros for continuation forms

From: Harry Spier (vasishtha.spier at gmail.com)
Date: Thu Sep 6 22:00:49 EDT 2012

To help myself understand continuations I created some macros to
simplify the syntax and to simulate keyword type arguments to make
whats happening more explicit.  I'm not sure the simulated keyword
type arguments are good Racket style but they helped me see what was
going on, by making things more explicit.  The forms are mainly let
type forms but there are some others There are also some examples that
helped my imperatively trained brain wrap around continuations.

For example I can now have this:
(define saved-continuation #f)
(define x 10)

(let/set-prompt ([prompt: prompt-1])
   (+ 4 (+ 3 (+ 2 (save-this-continuation
                              upto: prompt-1
                              in: saved-continuation
                              return: 0) x))))

(saved-continuation 0)
(set! x 100)
(saved-continuation 0)
Instead of:

((define saved-k #f)
 (lambda ()
   (+ 4 (+ 3 (+ 2 (call-with-composable-continuation
                   (lambda (k) ; k is the captured continuation
                     (set! saved-k k)
                     0) prompt-1) x)))) prompt-1)

 (saved-k 0)
 (set! x 100)
 (saved-k 0)

I thought others might find these macros useful so I uploaded the
macros and examples to Github:

Harry Spier

Posted on the users mailing list.