Proposal: __not(keyword)

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Sep 14 19:14:47 UTC 2018


On Friday, September 14, 2018 12:44:11 PM MDT Neia Neutuladh via 
Digitalmars-d wrote:
> On Friday, 14 September 2018 at 18:13:49 UTC, Eugene Wissner
>
> wrote:
> > Makes the code unreadable. You have to count all attributes in
> > the file, then negate them. Nobody should write like this and
> > therefore it is good, that there isn't something like __not.
> >
> > For @nogc, pure and so forth there were imho a better proposal
> > with a boolean value:
> > @gc(true), @gc(false), pure(true), pure(false) etc. It is also
> > consistent with the existing UDA syntax.
>
> The two proposals are extremely similar in effect. Under Adam D
> Ruppe's proposal, I could write:
>
> __not(@nogc) void foo() {}
>
> Here, @nogc wasn't set, so I didn't need to specify any
> attributes. If @nogc: had been specified a thousand times just
> above this function, __not(@nogc) would still make `foo` be
> not- at nogc.
>
> Identically, under your proposal, I could write:
>
> @gc(true) void foo() {}
>
> If this is the entire file, the annotation has no effect. If
> @gc(false) had been specified a thousand times just above this
> function, the annotation would still make `foo` be not- at nogc.
>
> There's no counting of attributes to negate. You just negate
> everything that doesn't apply to this function.

The main reason that attr(bool) is better is that it would allow you to do
stuff like use an enum for the bool, so its value could then depend on other
code, meaning that it would work better with metaprogramming. IIRC, at one
point, Andrei actually proposed that we add attr(bool), but it never
actually went anywhere. I expect that it would stand a good chance of being
accepted if proposed via DIP (especially if a dmd PR were provided at the
same time).

- Jonathan M Davis





More information about the Digitalmars-d mailing list