ChezScheme
ChezScheme copied to clipboard
Add support for SRFI-145?
I see more and more code relying on SRFI-145 aka. assume
A means to denote the invalidity of certain code paths in a Scheme program is proposed. It allows Scheme code to turn the evaluation into a user-defined error that need not be signalled by the implementation. Optimizing compilers may use these denotations to produce better code and to issue better warnings about dead code.
In particular the last sentence.
For what it's worth, I am using the following implementation:
(define-syntax assume
(syntax-rules ()
[(_ expression messages ...)
(meta-cond
[(fx=? (optimize-level) 3) (void)]
[else (unless expression
(let ([msgs (list messages ...)])
(errorf #f "invalid assumption ~s~@[ with message~p ~{~a~#[~;, and ~:;, ~]~}~]"
'expression (and (not (null? msgs)) (length msgs)) msgs)))])])))
What do you think?
Chez Scheme 10 now provides assert-unreachable, which can be used to faithfully and elegantly implement assume from SRFI 145.
https://cisco.github.io/ChezScheme/csug10.0/system.html#./system:s16