[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: assert() inside type x = struct { ...
From: |
Mohammad-Reza Nabipoor |
Subject: |
Re: assert() inside type x = struct { ... |
Date: |
Sat, 9 Apr 2022 17:29:40 +0430 |
On Sat, Apr 09, 2022 at 02:56:13PM +0200, apache2 wrote:
> > 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
It will return 1 on success (regardless of the actual value of argument,
because we expect a boolean as the first argument).