It seems pure ain't so pure after all

Jonathan M Davis jmdavisProg at gmx.com
Sun Sep 30 23:01:21 PDT 2012


On Monday, October 01, 2012 07:43:59 Alex Rønne Petersen wrote:
> This is a corner case.
> 
> __ctfe is there to allow special-cased CTFE code when absolutely
> necessary. By necessity, this separates a function into two worlds:
> compile time and run time.
> 
> As far as purity goes, pow2 *is* pure. It just does something different
> depending on whether you run it at compile time or run time. I don't see
> this as a problem in practice.

It would be kind of like complaining that a pure function returns different 
values on Linux and Windows due to a version statement or static if. It's just 
that in the thing that varies is compile time vs runtime not the target 
machine. e.g.

int func(int val) pure
{
    version(linux)
        return val + 2;
    else version(Windows)
        return val + 3;
}

- Jonathan M Davis


More information about the Digitalmars-d mailing list