(define with-dynamic-var (sym val f)
(define rec (f)
(match (reset (cons 'dyn sym) f)
({#finished, value} value)
({#shifted, {#lookup, cont}} (rec (thunk (continue cont val))))
({#shifted, {#mut, value, cont}} (with-dynamic-var sym value (thunk (continue cont))))
(rec f))
(define lookup (sym)
(shift (cons 'dyn sym) (lambda (c) {#lookup, cont: c})))
(define mutate (sym newval)
(shift (cons 'dyn sym) (lambda (c) {#mut, value: newval, cont: c})))
(with-dynamic-var 'x 5 (lambda ()
(f) ;; prints 5
(mutate 'x 10)
(f)) ;; prints 10
(define f ()
(print (lookup 'x)))