gnuplot returns the wrong array size for empty arrays. Although for datablocks it returns the correct number, but not for arrays.
Example:
$Data <<EOD
1
2
3
EOD
print |$Data|
$Data <<EOD
EOD
print |$Data|
array A = [1]
print |A|
array A = [1,2,3]
print |A|
array A = []
print |A|
Returns where the last 1 is not correct. Tested with gnuplot 5.4.6
3
0
1
3
1 # should be 0
True. But I'm curious. Did you find a way to end up with an empty array in version 5.4, other than simply creating it empty as in your test case?
The code in version 6 gets this right, and there it actually matters. When arrays became full-fledged variables in development version 5.5, empty arrays started to be a reasonable thing. You could operate on an array or create and return one from a function; in either case it might end up empty. For instance you could start with an empty array and add elements to it. I don't think there's any way to do that in version 5.4 so the question of how big the array currently is doesn't come up in practice. But maybe I'm missing something clever, which is why I ask if you found this via something more complicated that an empty declaration.
Anyhow, now fixed for 5.4.7
Thank you for the quick response.
You are right, there is probably no way in gnuplot 5.4 to create an empty array other than defining an empty one.
Since arrays are convenient in many cases, I was thinking about this when having a gnuplot template script and a programming language modifying it, e.g. with the output of a calculation, which is a sequence of numbers, but which could also be no number.
A simplified example:
If A is empty, instead of plotting nothing the script would fail because |A|=1 instead of =0 :
uninitialized user variable.