reflect on this function

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Feb 20 14:44:35 PST 2015


On Fri, 20 Feb 2015 22:32:53 +0000, Vlad Levenfeld wrote:

> I'd like to do something like this:
> 
>    @reflexive @transitive bool relation (T)(T a, T b)
>    out (result) {
>      mixin(property_verification!result);
>    }
>    body {
>      ...
>    }
> 
> which becomes
> 
>    out (result) {
>       // generated from @reflexive
>      assert (result == skip_contract!relation (b,a));
> 
>      // generated from @transitive static typeof(result) c;
>      if (result)
>        assert (skip_contract!relation (b,c) ==
> skip_contract!relation (a,c));
>      c = b;
>    }
> 
> or something like that. I don't see a way to get exactly this,
> but does anyone have any thoughts on something similar?

can you go with `relationImpl` and mixin/template that generates 
`relation` with contract then? something like:

  @reflexive @transitive bool relationImpl (T)(T a, T b) { ... }
  alias relation = buildWithContracts!relationImpl;

then you can simply call `relationImpl` in your out section.

sorry if i didn't understand what you want and just throws in some noise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150220/24b480e6/attachment.sig>


More information about the Digitalmars-d-learn mailing list