cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.97k stars 985 forks source link

Add support for SRFI-145? #488

Open amirouche opened 4 years ago

amirouche commented 4 years ago

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?

mnieper commented 5 days ago

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