Copying a snippet into HTML is where a documented language stops being the real one. Each block on the page is a program here with its recorded output beside it, and check.sh is what says the page is still true after a change.
25 lines
674 B
Plaintext
25 lines
674 B
Plaintext
(defstruct AssetMissing [id i32])
|
|
|
|
(defvar cleanups i64)
|
|
|
|
(defn load [n i32] i32
|
|
(signal (AssetMissing {:id n}))
|
|
100)
|
|
|
|
(defn middle [n i32] i32
|
|
(defer (set cleanups (+ cleanups 1))) ; runs on the transfer too
|
|
(+ (load n) 1))
|
|
|
|
(defn fetch [n i32] i32
|
|
(restart-case (middle n) ; its value if nothing transfers
|
|
(use-placeholder [] -1)
|
|
(retry [] 7)))
|
|
|
|
(defn main []
|
|
(print-i64 (i64 (fetch 1))) (newline) ; 101 — nothing handled it
|
|
|
|
(handler-bind [(AssetMissing [c] (invoke-restart 'use-placeholder))]
|
|
(print-i64 (i64 (fetch 2))) (newline)) ; -1
|
|
|
|
(print-i64 cleanups) (newline)) ; 2 — the defer ran both times
|