lua-users home
lua-l archive

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

On 1 January 2011 15:03, Henning Diedrich <> wrote:
> Hi Steve,

> "# is reverse magic. Dark magic, seen from the higher level. It requires
> understanding
> of implementation to 'become' intuitive. But without even the benefits of
> the usual
> over-eager white magic. Lua, for its purity, should shun both, of course."

I just don't understand it. What about the definition of # requires
understanding the implementation?

There are two ways you can look at the whole thing, quite simply:

1) Arrays can't have nil in them
2) The length operator returns the last index before a nil in an array

I have had cause to write code with both of these mindsets - sometimes
you want length to mean total length and sometimes you have an
algorithm where you just need to find a nil space to put some data in,
not caring whether it's at the end or in the middle.

People should stop trying to make the '#' operator anything else,
because it works perfectly fine as-is.