new contract syntax DIP

arturg via Digitalmars-d digitalmars-d at puremagic.com
Tue May 23 12:04:46 PDT 2017


On Tuesday, 23 May 2017 at 17:28:21 UTC, MysticZach wrote:
> I made a pull request for a new DIP dealing with contract 
> syntax:
>
> https://github.com/dlang/DIPs/pull/66
>
> I write the DIP in response to the discussions for DIP 1003: 
> http://forum.dlang.org/thread/wcqebjzdjxldeywlxjcd@forum.dlang.org
>
> This DIP is not under any kind of formal review yet. I just 
> wanted to let people know that it's there.

how about @uda based contracts?

@in(x => x < 100)
@out((ret) { assert(ret > 0, "some text"); })
int fun(int i) { return someVal; }

they could also be used on type definitions,

@out((t) { assert(t); })
  class NotNull {}

or temporarly on instances

@in(t => t !is null) auto notNull = new NotNull;

you could also have @inout as a combination.
another feature would be that they could be introspected.


More information about the Digitalmars-d mailing list