[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: New array type? (was: 'table' as fallback for tables)
- From: Philipp Janda <siffiejoe@...>
- Date: Fri, 1 Jul 2016 13:21:56 +0200
Am 01.07.2016 um 11:37 schröbte Dirk Laurie:
2016-07-01 9:20 GMT+02:00 Philipp Janda <siffiejoe@gmx.net>:
The "implementation details" are in fact of cardinal importance.
If the array is in fact kept entirely in the 'array' part, there is
bound to be an improvement in performance.
Have you encountered a case where the array is *not* kept entirely in
the 'array' part? This is not an easy thing to do without `nil`s. And if
you do have a sparse array, maybe you don't want to actually store all
those `nil`s.
In case you want to go looking: The getsize[1] module can tell you how
big array and hash part are, which in turn tells you where your integer
keys are stored ...
This doesn't solve the problem if `#` and the table functions
continue to accept regular plain tables.
There is no problem if the user obeys the rules.
Then what do we have error messages and stack traces for? You won't need
them if the user always obeys the rules.
The user chooses not to use the array option at his own peril.
We seem to have conflicting goals here. I want a fast array
implementation that does not need a calculation every time
I use #, does not need to resize an array except when I ask
it to by calling table.array myself, does not need to take into
account that an element may be in the has part.
What I think you want seems to have some law-enforcing
dimension to it that to my mind violates the spirit of Lua.
I've found some other examples of violations of the spirit of Lua:
> 1+"0"
1.0
> 1+""
stdin:1: attempt to perform arithmetic on a string value
> table.insert( {}, 1.3, true )
stdin:1: bad argument #2 to 'insert' (number has no integer representation)
> table.insert( {}, 5, true )
stdin:1: bad argument #2 to 'insert' (position out of bounds)
If a function or operator only works correctly for a subset of the
possible input values, why shouldn't it inform the user when he/she is
making a mistake? And why would such kindness be a violation of the
spirit of Lua?
Philipp
[1]: https://github.com/siffiejoe/lua-getsize