> >could you not try a simple test (not guaranteed to be 100% accurate 
> >though),
> >by copying the first data element and apply it twice and then check to see
> >that the result of applying it once is the same as applying it twice.
> 
> Feels a little too magic to me, and awfully fragile. I'm not comfortable
> doing that, though arguments to the contrary are welcome.

I agree that it isn't great, but I don't agree that it's really fragile
(although that may be difficult to prove conclusively). Take an earlier
example:

        (rand($x) <=> rand($y))

I suspect that the chances of rand($x) == rand(rand($x)) would be less than
1%. I would think that if it is different that you just raise a warning anyway
rather than doing anything special. There may actually be a case where someone
wants to have the side-effects (not that i can think of a reason immediately
off hand).

To be even handed an obvious counter-example is if the first data element is
say 1:

        squared(1) == squared(squared(1))

but clearly this is not an idempotent function. but the obvious question is if
it isn't an idempotent function what do we do? do we abort? perhaps the real
question is not whether we can require idempotency but what are we trying to
achieve with it --- there may be another way :)

peter

Reply via email to