Am Mi., 17. Juni 2020 um 10:15 Uhr schrieb Shiro Kawai <xxxxxx@gmail.com>:
>
> On Tue, Jun 16, 2020 at 10:00 PM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
>>
>>
>> `assume` should only do nothing in a mode that is equivalent to "-O3
>> -DNDEBUG=1".
>
>
> srfi-145 encourages so, but I always thought it is a hint to the implementation (such as type declarations in CL).
> At least, the code can't count on it raising an error.
Maybe we should add a (post-finalization) note to SRFI 145 that
(assume x)
should be equivalent to what the following would be in the GCC:
#ifndef NDEBUG
assert (x);
#else
if (!x) __builtin_unreachable ();
#endif
> So, the issue comes down to whether you accept (maybe-ref (nothing)) can return #f. Now I think about it, I can always say (maybe-ref obj (cut error "whatever")) if I want to throw an error, so just writing (fn (maybe-ref obj)) for an extra (optional) check may be convenient. Assuming fn is prepared to get #f when obj is Nothing.
Note that, strictly speaking,
(maybe-ref (nothing) (lambda () (assume #f)))
is an error (which is the same as UB in C) to make aggressively
optimized compilation possible. So the value can likewise be #t or the
expression may not even deliver any values to its continuation.