lua-users home
lua-l archive

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


Am 03.07.2016 um 18:43 schröbte Dirk Laurie:
2016-07-01 13:21 GMT+02:00 Philipp Janda <siffiejoe@gmx.net>:
Am 01.07.2016 um 11:37 schröbte Dirk Laurie:
2016-07-01 9:20 GMT+02:00 Philipp Janda <siffiejoe@gmx.net>:

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.

This is a straw man argument. I have never suggested for one
moment that there should not be error messages and stack
traces.

The point was that you won't ever see error messages or stack traces if you always obey the rules. So they must be superfluous, right? Unless people, for some reason, don't always follow the rules, and then error messages and stack traces become very useful ...


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:

Another straw man argument. I did not say that there are no
existing violations of the spirit of Lua. I said that enforcing
laws is against the spirit of Lua. "Lua provides mechanisms,
not policies."

I don't know where the spirit of Lua stops and where the practical compromises start, but there are similar cases to the one proposed (correct type, but invalid value), where Lua chooses to raise an error. That certainly isn't the only option: I believe `1+""` is legal in Javascript (or was it PHP?).

IIRC, the reason why Lua doesn't check for valid sequences is that it is expensive to do. But if we change the way Lua represents arrays, we could fix that -- unless we continue to support sequences as a fallback.


Naturally the user would be informed of a mistake. But it is
not a mistake to use a table function in the way it has always
been done in Lua.

I think it boils down to the question whether passing a non-sequence to a table function or the `#` operator is a mistake or not. Lua says it's undefined, and I do see it as a mistake, YMMV.

In fact. that is still the only way to work with arrays of variable
length.

You lost me there. Most of the proposals in this thread are about variable length arrays (including yours, actually). One of the interesting questions is under which circumstances the length should change.


My proposal is that there should be a fixed-length array,
allowing implementors to optimize for speed.

I'm not sure you'll get much speed out of this. There's not much you can do except represent the array data as a C style array, which Lua already does. You'd probably be able to save some memory though.


Philipp