|
On Oct 2, 2013, at 1:53 PM, Sean Conner <sean@conman.org> wrote: Now, I'm harping on the sum example because that's the example you The sum was purely an example to illustrate the difficulty in creating a robust API. The issue here is the behavior of # when arrays have holes are can thus be viewed either as a "array with holes" or a "array with other integer keys after the end of the array". # gives odd results in these cases, which means (to my mind) its risky to use # when an array is not well-formed. And thus I find it desirable to check to see if an array is well-formed before using # .. but there is no way to do this in Lua that is not O(n). If this were all my code base, then, as others have suggested, the solution is "make sure you don't create ill-formed arrays", but it's NOT all my code base and I need to be defensive when writing APIs to be consumed by others. --Tim |