Length of a sequential table in Lua may skip indices? [duplicate] - lua

This question already has answers here:
An Interesting phenomenon of Lua's table
(2 answers)
Closed 9 years ago.
In Lua is seems that if a single numeric key is missing from the table, the length still continues counting:
> print(#{[1]=1,[2]=2,[4]=4})
4
But this skipping two indices stops at the break
> print(#{[1]=1,[2]=2,[5]=5})
2
It's not just the unconvential constructor. Even if an skipped index is created after the creation of the table it still counts past it, so long the break is only one.
> x={1,2}
> print(#x)
2
> x[4]=4
> print(#x)
Is this an implementation error or is this how Lua supposed to work. Why is it like this? Any references to documentation of this would be interesting.

This is how it works. The length of a table is only defined if the table is a sequence, with no holes. See http://www.lua.org/manual/5.2/manual.html#3.4.6 .

Related

Google Sheets Less than or equal (<=) provide wrong result [duplicate]

This question already has answers here:
Difference in value of two same time google Sheets [duplicate]
(1 answer)
Is floating point math broken?
(31 answers)
Why are floating point numbers inaccurate?
(5 answers)
Closed 8 months ago.
Formula 0<=(1.36*100/1.36)-100 returns FALSE while expects TRUE.
But
0<=(1.26*100/1.26)-100 returns correct result TRUE.
Why?
if you run:
=(1.36*100/1.36)-100
and expand decimal places you will get:
which is totally fine even if you do not expect such behavior. this is due to how google sheets stores the numbers and this "nonsense" is called "rounding error" (yet it is not an error)
see: https://stackoverflow.com/a/72230592/5632629
in your case try:
=0<=ROUND((1.36*100/1.36)-100)

Is there the equivalent of INT_MAX in dart? [duplicate]

This question already has answers here:
Is there a constant for max/min int/double value in dart?
(5 answers)
Closed 2 years ago.
The question is in the title: is there a constant INT_MAX (the maximum value of an integer) in the Dart language?
I don't care what it is, I just want to use it as an initialization constant to, for example, find a minimum value in a List.
I note that there is a double.maxFinite which I could use as in
int i = double.maxFinite.toInt();
but that somehow seems wrong to me. Or is it?
There is no maximal integer value across Dart platforms.
On native platforms, the maximal value is 0x7FFFFFFFFFFFFFFF (263-1). There is no constant provided for it.
On web platforms, the maximal integer value is double.maxFinite.
If I had to do something which needed an initial maximal value (finding the minimal element of a list, perhaps), I'd prefer to start out with the first element, and throw on an empty input.
As a second choice, I'd use num for the accumulator and use double.infinity as starting value. Then I'd check at the end and do something useful if the value is still infinite.

replace text in TeX [duplicate]

This question already has answers here:
Is there any way I can define a variable in LaTeX?
(5 answers)
Closed 5 years ago.
Is there a way to add a text by reference using LaTeX? I have several text references to 'versionXX.yy'. I wonder if I can define this in one place so I don't need to update it in all places.
Thanks
You could define a variable or new command with your version at the beginning and then just use this definition. See here
Btw. there is a special site called tex.stackexchange.com for this kind of questions.

Command line parsing in Tcl [duplicate]

This question already has answers here:
how to create tcl proc with hyphen flag arguments
(4 answers)
Closed 7 years ago.
I have a script that will require many short and long options and was wondering what would be the most efficient way to parse the command line arguments. Using for-each and if-else would make the code too long and difficult to modify, so is there be any standard function that can help me (something like getopt for C)?
We discussed this four days ago and a few suggestions were posted.
There is also the cmdline package in Tcllib.

How to determine whether a linked list contains a loop? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
find whether a loop in a linked list without two pointers
How to determine if a linked list has a cycle using only two memory locations.
Best algorithm to test if a linked list has a cycle
During a preparation for a job interview, I encountered the following question:
How can you determine whether a linked list (of any type) contains a loop, using additional space complexity of O(1)? You cannot assume that the loop starts at the first node (and of course, the loop doesn't have to contain all nodes).
I couldn't find the answer, though I have the feeling it's quite simple...
Easy. Maintain two pointers into the list. At each step, advance one pointer by a single link, and advance the other by two links. Test to see if they point to the same element. If so, you have a loop. If not, repeat until you find a loop or you reach the end of the list.
Probably the same technique as checking if a graph is a tree (trees don't get to have cycles), see this this question. It recommends either a topological sort or a depth first search.
I had this exact problem in real live code last week.
All I did was kept a pointer (link) for the first element. Then as I iterated through the list, if I ever got that pointer again, I know there's a loop.

Resources