lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Miles Bader <miles <at>> writes:
> chris <csrl <at>> writes:
> > I would be interested to understand the intended purpose of the
> > length operator for tables then.  As I see it, you have to know that
> > the table is a sequence in order to find the length operator useful.
> Yes (but of course, it's the usual case that one does know how one's
> data structures are structured ... :)

Not in the context I'm working within.  The issue nearly becomes a mute point if
one knows the data structure, and so wouldn't be under discussion.

> > If you know it is a sequence, that means you could have already
> > tracked the length manually
> Sure, you _could_, but why would you want to, when the # operator does
> the right thing, and is more convenient (and in many cases more
> efficient)?

Because one already has to track the length in the case that an index might be
assigned nil.  As such there is no benefit to having the efficiencies of the
length operator if that is ever a possibility.  This discussion wouldn't be
taking place if we were all working only with sequences.  As I mentioned in
another post, because the table.* functions want to work only with sequences, it
makes better sense to expose the sequence length through a table.len() function
to avoid this type of confusion.

At this point I think I've said everything pertinent to where I'm coming from,
and anything else is just going to be point counter point.

Thanks for the responses.  I hope at some time this particular area will flesh
out.  Lua 5.2 is allowing us to do some very cool things out of the box.