ALEN()
- kevclark64
- Posts: 127
- Joined: Thu Aug 15, 2019 7:30 pm
- Location: USA
ALEN()
I noticed that if you have an array of dimension 5,2 then ALEN(array) in Foxpro would return 10 but ALEN(array) in X# returns 5. Foxpro has an extra parameter to ALEN to return rows or columns, which X# does not support currently. However passing just the array gives the total elements across all dimensions in Foxpro. The FoxPro function list mentions ALEN as a function which works but not exactly with the same parameters. But it seems like if the same parameter is passed then it would be good to get back the same result.
ALEN()
Kevin,
The potential problem that I see with FoxPro arrays is that they are not really multi dimensional, but they emulate multi dimensions. Consider the following code
In most of the other dialects this mixing of single and multi dimensional approach will not be possible.
When you declare an array as [5,2] then the first element of the array is a sub array of 2 elements.
Assigning 10 to it would remove the sub array in the first element and accessing it with a 1,1 index later would cause an exception because the sub array has been replaced with a single numeric value.
And in other XBase dialects accessing element myarray[2] would return an array of 2 elements and not a single value.
I am sure that internally FoxPro uses single dimensional arrays always and it somehow calculates the position in this array by calculating a single dimensional offset in the array from the dimensions used.
And FoxPro even allows to use positions outside of what has been defined !
I personally think this was a design flaw in FoxPro. An array that is declared as multi dimensional should not allow to be treated as single dimensional and accessing 'undefined' positions show throw an exception.
Robert
The potential problem that I see with FoxPro arrays is that they are not really multi dimensional, but they emulate multi dimensions. Consider the following code
Code: Select all
DIMENSION myarray(5,2)
? ALEN(myarray)
myarray[1] = 10 && this sets element [1,1]
myarray[1,2] = 12
? myarray[1,1] && 10
? myarray[2] && 12, so this reads element [1,2]
FOR i = 1 TO 10
? i, myarray[i]
myarray[i] = i
NEXT
* you can even access undefined columns and rows
* in other xbase dialec ts all of the following would crash
? myarray[2,4] && 6 ?
? myarray[3,3] && 7 ?
? myarray[9] && 9 ?
When you declare an array as [5,2] then the first element of the array is a sub array of 2 elements.
Assigning 10 to it would remove the sub array in the first element and accessing it with a 1,1 index later would cause an exception because the sub array has been replaced with a single numeric value.
And in other XBase dialects accessing element myarray[2] would return an array of 2 elements and not a single value.
I am sure that internally FoxPro uses single dimensional arrays always and it somehow calculates the position in this array by calculating a single dimensional offset in the array from the dimensions used.
And FoxPro even allows to use positions outside of what has been defined !
I personally think this was a design flaw in FoxPro. An array that is declared as multi dimensional should not allow to be treated as single dimensional and accessing 'undefined' positions show throw an exception.
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 200
- Joined: Wed Oct 09, 2019 6:51 pm
ALEN()
True and it will bite you if you ReDim without first saving contents to re-populate redimensioned array.robert wrote:I am sure that internally FoxPro uses single dimensional arrays always and it somehow calculates the position in this array by calculating a single dimensional offset in the array from the dimensions used.
Array functionality was added early in the DOS years - and Fox made certain old programs will run in new versions. That kept some code p[w]arts alive...As in xSharp typed arrays should be the target to aim for, relegating such crazy behaviour to USUAL datatype hopefully will eliminate it from user code in time.I personally think this was a design flaw in FoxPro. An array that is declared as multi dimensional should not allow to be treated as single dimensional and accessing 'undefined' positions show throw an exception.
my 0.002€
thomas