Is this function pure?

Janice Caron caron800 at googlemail.com
Tue Sep 18 06:54:17 PDT 2007


On 9/18/07, Lutger <lutger.blijdestijn at gmail.com> wrote:
> Janice Caron wrote:
> > Is this function pure?
>
> Putting what the compiler can check aside, isn't it the return statement
> in the catch block what prevents this function from being pure, or
> referentially transparent?

I don't think so, since I could easily rewrite it as

int probablyNotPure(int x)
{
    int n;
    try
    {
        char[] a = new char[x];
        n = a.length;
    }
    catch
    {
        n = 0;
    }
    return n;
}



More information about the Digitalmars-d mailing list