On 1/4/11 7:59 AM, Simen kjaeraas wrote:
Guilherme Vieira <[email protected]> wrote:

@Walter: would it be hard/impossible for the compiler to look at
memoize and
tell it exhibits pure behavior and is, thus, pure?

The simplest solution is this:

template memoize( alias fn ) {
static if ( isPure!fn ) {
pure auto memoize( ParameterTypeTuple!fn ) {
// Blah!
}
} else {
auto memoize( ParameterTypeTuple!fn ) {
// Blah!
}

}
}

I've been mulling over this for a while, maybe it's time to start discussing it.

Often you want to say "this entity is pure/const/immutable/safe... if this other entity is the same, or generally if this Boolean is true". So I was thinking of introducing e.g. a constrained pure:

template memoize( alias fn ) {
    pure(isPure!fn) auto memoize( ParameterTypeTuple!fn ) {
        ...
    }
}

So generally when you write "attribute(expression)" the attribute will be in effect if and only if the expression is true.

D has become very powerful at introspecting most of its own abstractions in the form of compile-time Booleans. This language extension would close the circle by allowing D to introduce attributes and qualifiers depending on compile-time Booleans.


Andrei

Reply via email to