lua-users home
lua-l archive

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


2016-07-22 1:46 GMT+02:00 Tim Hill <drtimhill@gmail.com>:

> Personally, I admire Lua not only as a very practical language but also
> one which is aesthetically elegant.

Hear, hear!

My take on these discussions (of which we have had an inordinate
number recently) is that they are very much like those between
supporters of a football team. The participants are talking about
something they love passionately and often know very well. They
critically evaluate the performance of the team, and each is absolutely
convinced of having got a brilliant idea that so far has completely
escaped the notice of the manager, captain etc.

The chance that any particular idea will actually be taken up by the
manager and captain is remote, but that does not deter the fans.
They are having fun, even if the arguments do get heated.

> The reason I dislike the current “sequences cannot have holes” design
> is (a) it is peculiarly at odds with the clean simple design of the rest
> of the language (even the definition of sequence, though correct,
> is not intuitive),

Oh, there is no design to it. The notion of a sequence is only the most
recent in a long series of attempts to disguise an implementation detail
as a concept. Don't blame the design; blame the documentation.

Here is some history from present to past.

5.3 The table library respects __index, i.e. accesses are no longer raw.
5.2.2 Illegal indices to table.insert and table.remove are flagged as
errors instead of silently causiing something silly.
5.2 The table library respects __len, and the notion of 'sequence' finds
its way into the manual. The word "hole" is not used.
5.1 The word 'length' is used for the result of the new # operator,
and the notion of "hole" is used to describe something that "regular
arrays" do not have.
5.0 Table manipulation is collected into the 'table' library. The "size"
of an array could be some hidden internal register that you can set
with 'setn',
4.0 'tinsert' and 'tremove' appear as global functions. The notion
of "size" of an array is used, which is either an explicit 'n' field
or the number of elements before the first hole (but the word "hole"
is not used).

"size", "length", "hole", "regular array", "sequence" -- from the
documentation you will get the impression that the table library
has been rewritten many times, but that is true only of the
way length is defined. The way that it is computed is almost
the same right through: there is a mechanism to set length
explicitly, otherwise the loop stops at a hole.

> and (b) appears to confuse a pretty significant number of people
> judging by how often it comes up on this list.

You can't blame folk for trying to read the manual :-) but in
this case most people would be better off with just a couple
of examples of what insert and remove do.

The subtle thing is the length operator, and it will stay subtle as
long as we want a faster than O(n) way of computing it. Personally
I found the definition in the Lua 5.1 manual very clear, and would
like to have it back. I don't object to the word "hole" either. It was
taken out of the manual more than five years ago, but everybody
still uses it.