an old topic (pun intended)

Davidson Corry davidsoncorry at comcast.net
Thu Oct 27 19:55:03 PDT 2011


On 10/27/2011 2:12 PM, Timon Gehr wrote:
> Yes, this design has indeed a keyword-issue that your proposal has not.
> I am all for not making it a keyword. The 'body' keyword imho should be
> removed too, there is only one place in the grammar where it is ever
> needed (and there it is completely redundant), therefore it could just
> be lexed as an identifier. That would not break any code.

Agreed. In fact, it occurred to me the other day that we could write 
contracts as

     void foo(T t)
     {
         scope(in) {
              // pre-condition contracts
         }
         scope(out) {
              // post-condition contracts
         }
         // ...body of function...
     }

and eliminate the 'in', 'out' and 'body' keywords/constructs entirely.

Similarly, an invariant could appear in the default constructor of a 
class as

     this()
     {
         scope(invariant) {
             // invariant guarantees...
         }
         // ...body of constructor...
     }

Or *any* constructor, really, although you would probably want the 
compiler to enforce that no more than one constructor defined a 
scope(invariant) block. This notation also suggests (correctly) that the 
invariant doesn't take effect until you have entered the constructor. 
(Exited it, really, but...)

-- Davidson


More information about the Digitalmars-d mailing list