Is this function pure?

0ffh spam at frankhirsch.net
Tue Sep 18 12:19:01 PDT 2007


Janice Caron wrote:
> 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?

That's surely a point which can be discussed:

I could, for example, say: A result of 0 happens only in case of an
error condition. Sure, you loose functional purity then, but there's
just nothing you can do about that. (Actually, in *this* special case
you could do something about it, but not in the general case.)

Your function could return 23, because a lump of radiation hit the
stack memory and flipped two bits. That's just to bad, but that's it.

Therefore: In case of errors, there's an exception!
(And, in this case, a double entendre. :-)

Regards, frank



More information about the Digitalmars-d mailing list