[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assert() inside type x = struct { ...
From: |
apache2 |
Subject: |
Re: assert() inside type x = struct { ... |
Date: |
Sat, 9 Apr 2022 14:56:13 +0200 |
User-agent: |
Mutt/1.9.3 (2018-01-21) |
> What do you think about chaning the `format` to be an expression of type
> `int`?
> That way users can do something like this:
>
> ```poke
> struct
> {
> int field1;
> int field2;
>
> var a_descriptive_variable_name = assert (some_condition, "...");
> };
>
> ```
>
> If you agree with this, I can send the patch.
Hmm, does that mean that regular
assert(1);
would trigger a compiler warning that the user is throwing away the result?
it would kind of make sense/be useful if assert() would return the result, like:
var not_zero = assert(2+2);
// not zero == 4
An alternative might be to allow casting "void" to int like:
var myvar = assert(1) as int;