| 1 |
;; SRFI-145 chez scheme implmentation |
| 2 |
;; |
| 3 |
;; Uses Chez Scheme's meta-cond to suppress generating the assumption code when |
| 4 |
;; compilled at optimize-level 3. Otherwise it uses the Chez Scheme errorf |
| 5 |
;; procedure to raise a nicely formatted exception when the assumption fails. |
| 6 |
;; |
| 7 |
;; Copyright (c) 2018 - 2020 Andrew W. Keep |
| 8 |
|
| 9 |
(library (srfi :145 assumptions) |
| 10 |
(export assume) |
| 11 |
(import (chezscheme)) |
| 12 |
|
| 13 |
(define-syntax assume |
| 14 |
(syntax-rules () |
| 15 |
[(_ expression messages ...) |
| 16 |
(meta-cond |
| 17 |
[(fx=? (optimize-level) 3) (void)] |
| 18 |
[else (unless expression |
| 19 |
(let ([msgs (list messages ...)]) |
| 20 |
(errorf #f "invalid assumption ~s~@[ with message~p ~{~a~#[~;, and ~:;, ~]~}~]" |
| 21 |
'expression (and (not (null? msgs)) (length msgs)) msgs)))])]))) |