Is this function pure?

Janice Caron caron800 at googlemail.com
Tue Sep 18 11:37:54 PDT 2007


On 9/18/07, 0ffh <spam at frankhirsch.net> wrote:
> Janice Caron wrote:
> > Is this function pure?
> >
> > int probablyNotPure(int x)
> > {
> >       try
> >       {
> >               char[] a = new char[x];
> >               return a.length;
> >       }
> >       catch
> >       {
> >               return 0;
> >       }
> > }
>
> Functional purity has only these conditions:
>
> * The result is a function of the parameters, and only of the parameters.
> * Variables can be created and duplicated, but not changed.
>
> I don't see your example violating these conditions.

You don't? The way I see it, if the input is 5, then output might
sometimes be 5 and sometimes be 0. That would seem to violate your
first bullet-point, would it not?



More information about the Digitalmars-d mailing list