Is this function pure?

Ingo Oeser ioe-news at rameria.de
Tue Sep 18 12:22:18 PDT 2007


Janice Caron wrote:

> OK, so change it to
> 
> char[] probablyNotPure(int x)
> {
>       try
>       {
>               char[] a = new char[x];
>               return a;
>       }
>       catch
>       {
>               return null;
>       }
> }
> 
> and consider that the input might be 0x7FFFFFFF.
> 
> I think it looks less easy to optimise now.

Ok, now that's impure, since now you are using the memory by returning it.
This is really not side effect free. You are draining a global resource,
which is a no-no for pure functions. All the discussions and points
raised by the other people now apply.


Best Regards

Ingo Oeser



More information about the Digitalmars-d mailing list