News for hackers. Stuff that matters.
Re:What's New in Lua 5.4 by samatman on Wednesday July 15, 2020 @09:31PM (#23854745)
I work with Lua extensively, including abstract syntax trees.

To mark a node at the third position, containing one character, we say {3,3}.

But what if there's a node at the third position, that contains no character? Well, thats {3,2}.

It's like nails on a chalkboard every time. 1-based indexing is a mistake.

~=, by contrast, is just notation. You get used to it quickly.

Re:What's New in Lua 5.4 by saagarjha on Wednesday July 15, 2020 @09:44PM (#23854823)
> To mark a node at the third position, containing one character, we say {3,3}. > But what if there's a node at the third position, that contains no character? Well, thats {3,2}

Why not shift over indexing by one consistently? So you'd use {3, 4} and {3, 3} for each, so the length property is preserved.

Re:What's New in Lua 5.4 by samatman on Wednesday July 15, 2020 @10:07PM (#23854965)
Because that's not how the string library works.

("12345"):sub(3,3) returns "3", while ("12345"):sub(3,4) returns "34", and ("12345"):sub(3,2) returns "".

Indexing in the array portion of tables, and strings, is at least consistent; but Djikstra was right.

The Wiki[0] has a good discussion of Djikstra's iconic essay. The best of these arguments, imho: 0 based indexing unifies enumeration and measurement.

[0]: https://wiki.c2.com/?WhyNumberingShouldStartAtZero

Re:What's New in Lua 5.4 by int_19h on Thursday July 16, 2020 @02:57AM (#23856532)
That's an argument against end-inclusive ranges more so than against 1-based indexing. If they were end-exclusive, like in Python, then {3,3} would be an empty string, and {3,4} would be a single character at 3. Note how it suddenly doesn't matter at all whether the indices are 0-based or 1-based - all of the above is valid regardless.

FWIW, I think that the real mistake was to make inclusivity/exclusivity implicit to begin with. If the syntax is explicit, and the choice is captured in the resulting value (i.e. it's more than just a pair of numbers), then you just use whatever is more convenient for the task at hand. Nim almost gets there: (x .. y) is end-inclusive, and (x ..< y) is end-exclusive - but the syntax still exhibits a preference.

Re:What's New in Lua 5.4 by pwdisswordfish2 on Thursday July 16, 2020 @03:26AM (#23856670)
Thing is, end-exclusive ranges go hand-in-hand with zero-based indexing. I don’t think I need to link the EWD article.
Re:What's New in Lua 5.4 by int_19h on Thursday July 16, 2020 @05:56AM (#23857380)
I don't find it particularly persuasive. End-exclusive and end-inclusive can both be natural in different scenarios, regardless of the base - the article simply cherry-picks the ones that it needs to "prove" its case. That's why it's best when the language just offers both.
Re:What's New in Lua 5.4 by pansa2 on Thursday July 16, 2020 @03:54AM (#23856794)
> Nim almost gets there: (x .. y) is end-inclusive, and (x ..< y) is end-exclusive - but the syntax still exhibits a preference.

Swift is similar, using `...` and `..<`. Rust uses an alternative convention, `..=` and `..`.

Would you prefer to see `..=` and `..<` so that inclusivity/exclusivity is always explicit?

Re:What's New in Lua 5.4 by int_19h on Thursday July 16, 2020 @04:23AM (#23856934)
Yep, pretty much. I'm a strong proponent of "explicit is better than implicit" in all cases where there's no default that's obviously preferable, and this is is one of those cases - that different languages picked different defaults is all the evidence I need.