Feature request: Optional, simplified syntax for simple contracts

Manu turkeyman at gmail.com
Sat Jun 15 17:19:24 PDT 2013


Super awesome idea! How about coma separated expressions to perform
multiple asserts?

int func(int i, int j) in(i<5, j<10)
{
  return i + j;
}


On 16 June 2013 07:45, TommiT <tommitissari at hotmail.com> wrote:

> "Simple things should be simple, complex things should be possible." -Alan
> Kay
>
> I'd like to simplify the syntax of function pre- and post-conditions when
> the contract block consists of a single assert statement. A special syntax
> for this special case would omit all of the following:
> 1) the block's curly braces
> 2) the assert keyword
> 3) the semi-colon ending the assert statement
> 4) the body keyword (if and only if it follows right after the block)
>
> So, instead of writing this:
>
> int func(int i)
> in
> {
>     assert(i < 5);
> }
> out(r)
> {
>     assert(r < 9);
> }
> body
> {
>     return i * 2;
> }
>
> ...you'd be able to write this:
>
> int func(int i)
> in (i < 5)
> out(r) (r < 9)
> {
>     return i * 2;
> }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130616/53f6d939/attachment.html>


More information about the Digitalmars-d mailing list