lua-users home
lua-l archive

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


> In my opinion, this sort of non-intuitive behaviour, which needs
> very careful reading of the reference manual to understand, is
> a much greater evil than the alleged illogic and Cobol-likeness
> of making s[3] mean the third character of the string s.  But
> I promised to stop ranting about this.

IMHO the best argument given has been the reference to (future?) UTF8
portability. The n-th character from a string with UTF8 characters is
a nontrivial operation with O(n) costs. It is not necessarily the n-th
byte or like C suggests a 0-indexed array. From gut-feeling I'd
support your effort, but the more I see talked about it, the less I
see the goods of string[n].

In the sense of defensive coding, I'd like to see an error thrown much
rather than a nil returned tough.

Kind regards, Axel

PS: Maybe I missed it, but sometimes I think some users could take
advantage of a general purpose lua-expansion (not to call it bloating
:-) library. Without any C-extensions, lua only, a library that
contains all the things that can be easily being coded, but which are
not included in slim and beautiful Lua. Similar to prototype.js that
does provides some additional Framework to javascript. Aside for some
string magic, it might contain standard implementations for say binary
trees (different kinds of), b+-trees, special logic for lists chunks
with holes, read-only references to tables, white-list prototypes (a
table that only allows a given set of keys), globals locking, etc.
Dunno, maybe the idea is un-lua-ish from start, maybe it exists
already.