[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Definition of table.insert
- From: "hd2010@..." <hd2010@...>
- Date: Tue, 11 Jan 2011 10:01:01 +0100
thanks for that comprehensive list.
All points are good, you are hedging a bit too much l guess to pinpoint disagreement. Second part of 3 indicates the problem, 4 is tru but the intention spoken of is currently implemented self defeatingly. Undefined behavior 'should' not be producable in the first place but at least not as in passing and unwittingly to the beginner as in 3, and the condition listed in 5 'should' simply result in errors instead.
4/6 are projecting the problem zone nicely: either help better to abide, or help realizing when you are in violation. It would not even be hard, and Lua, is not C or Assembler after all. And, it's probably close to perfect as it is. Just not in this minuscule respect.
For Lua, "undefined" 'should' not be a respectable option.
On Tue, Jan 11, 2011 at 09:05:12AM +0200, Henning Diedrich wrote:
> You also stress by that, that table must not be seen as one type, but two
> in one. I would suggest that's also too complicated. A table should not
> behave differently depending on how it has been treated before. Simple
> as that in my eyes.
Undefined behavour is just that: undefined.
Could you narrow down your objection as a disagreement with one of the
1. Lua has one and exactly one sophisticated data structure: a table,
which is a map from a set of keys to a set of values. Both these
sets are subsets of the set of first-class values.
2. nil is not a first-class value and may therefore not be either
a key or a value. Constructions like
if t[a]==nil ...
are nothing else than translations of statements like
"If t does not contain the key a ..."
"Remove b from the set of keys of t"
into Lua syntax.
3. The keys 1,2,3,...,n occur particularly often, and for our convenience,
a table constructor is provided that implicitly assigns those keys
so that we need only specify values. A nil value given to that
constructor means: don't associate anything with that key just yet.
4. Certain functions such as ipairs, #, table.insert and table.remove
are designed to make life easier for us when the numeric keys in
our table form just such a continuous block.
5. If you wish to use those functions, you should not use any numeric
keys outside the block, and also not allow any key properly inside
the block to be removed.
6. Lua does not actually check that you have been law-abiding when you
do use these functions, but (except ipairs and to some extent #)
the result is undefined and you should not rely on any property
that in a particular implementation they have been observed to