in reply to Re^5: reduce like iterators
in thread reduce like iterators

In general and in theory, no.

But lots of people have so done, and it works out reasonably well in practice. For a random example Dominus used char(20) for this purpose in the widely used Memoize. (Then documented the limitation.) This code is significantly faster than a robust escape mechanism would have been, and he provided a mechanism to fix the potential bug if you needed to.

Replies are listed 'Best First'.
Re^7: reduce like iterators
by LanX (Saint) on Jan 19, 2011 at 12:53 UTC
    I know and agree that the probability of a bug is much smaller when using a magic string, and at the end "bug-freeness" of non-trivial code is only a product of probabilities.

    In other words IT isn't math!

    But I prefer solutions where I don't have to document (and keep in mind) rare side cases.

    Especially in this case, simulating reduce's approach to start with the first two values is clean and elegant.

    Cheers Rolf