Is this function pure?
Lutger
lutger.blijdestijn at gmail.com
Tue Sep 18 06:39:48 PDT 2007
Janice Caron wrote:
> Is this function pure?
>
> int probablyNotPure(int x)
> {
> try
> {
> char[] a = new char[x];
> return a.length;
> }
> catch
> {
> return 0;
> }
> }
>
> I must assume not, since it's not deterministic. But which part of it
> wrong? Should "new" be forbidden? Or is "try/catch"? Or both?
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?
More information about the Digitalmars-d
mailing list