digitalmars.D.learn - reflect on this function
- Vlad Levenfeld (21/21) Feb 20 2015 I'd like to do something like this:
- ketmar (7/32) Feb 20 2015 can you go with `relationImpl` and mixin/template that generates=20
- Vlad Levenfeld (4/9) Feb 20 2015 Yeah, this looks pretty good. As much as I hate the pimpl idiom,
- ketmar (3/15) Feb 20 2015 and you can have an alias even before definition! ;-) this way it will=2...
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (29/50) Feb 20 2015 Apparently, __FUNCTION__ is valid in an out block:
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?
Feb 20 2015
On Fri, 20 Feb 2015 22:32:53 +0000, Vlad Levenfeld wrote:
I'd like to do something like this:
=20
reflexive transitive bool relation (T)(T a, T b)
out (result) {
mixin(property_verification!result);
}
body {
...
}
=20
which becomes
=20
out (result) {
// generated from reflexive
assert (result =3D=3D skip_contract!relation (b,a));
=20
// generated from transitive static typeof(result) c;
if (result)
assert (skip_contract!relation (b,c) =3D=3D
skip_contract!relation (a,c));
c =3D b;
}
=20
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=20
`relation` with contract then? something like:
reflexive transitive bool relationImpl (T)(T a, T b) { ... }
alias relation =3D 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.=
Feb 20 2015
On Friday, 20 February 2015 at 22:44:35 UTC, ketmar wrote:
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.
Yeah, this looks pretty good. As much as I hate the pimpl idiom,
having a one-liner alias right next to the definition should
minimize the eye-bleeding. Thanks!
Feb 20 2015
On Fri, 20 Feb 2015 22:51:21 +0000, Vlad Levenfeld wrote:On Friday, 20 February 2015 at 22:44:35 UTC, ketmar wrote:and you can have an alias even before definition! ;-) this way it will=20 not lost.=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 =3D buildWithContracts!relationImpl; then you can simply call `relationImpl` in your out section.=20 Yeah, this looks pretty good. As much as I hate the pimpl idiom, having a one-liner alias right next to the definition should minimize the eye-bleeding. Thanks!
Feb 20 2015
On 02/20/2015 02:32 PM, 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?
Apparently, __FUNCTION__ is valid in an out block:
import std.stdio;
import std.string;
struct reflexive
{}
struct transitive
{}
string property_verification(alias var)(string func = __FUNCTION__)
{
return format(
`writefln("We are in %s; and the value of '%s' is '%%s'.", %s);`,
func, var.stringof, var.stringof);
}
reflexive transitive bool relation (T)(T a, T b)
out (result) {
mixin(property_verification!result);
} body {
return false;
}
void main()
{
int a, b;
relation(a, b);
}
The output printed inside the out block:
We are in deneme.relation!int.relation; and the value of 'result' is
'false'.
Ali
Feb 20 2015









ketmar <ketmar ketmar.no-ip.org> 