Input needed on FoxPro array support
Posted: Mon Nov 23, 2020 9:07 pm
We are working on the implementation of the FoxPro array support.
From what we have seen the FoxPro arrays are one dimensional arrays that also support a 2 dimensional indexes.
You can declare an array like this
and then access
myArray(4) and see the value 4.
or
Redimension the array to
and see that the contents has been saved and the elements have the values 1 through 4.
We have this working.
However this works quite different from the array support that we already have in the system, which is based on the Clipper array support (sometimes also called Ragged Arrays) where each array is in fact a single dimensional array, but the elements of the array can also be arrays, which allows unlimited nested arrays. This array support is also available in Visual Objects, Vulcan and Xbase++.
The questions that we have are:
1) In the FoxPro dialect should there be both the FoxPro compatible arrays (for example declared with the Dimension keyword) and Clipper compatible (Ragged) arrays ? Or should we map the ARRAY keyword in the FoxPro dialect to the special FoxPro array type?
2) There are many functions in the FoxPro runtime that take an not declared, unitialized array and fill the array. See for example this code from the VFP helpfile:
As you can see gaDatabase is not declared and not initialized. The runtime magically creates the array inside the ADatabases() function and adds it as private to the function that called it.
In most other XBase dialects you would write it like this
or
How common is this kind of code (like the example from the help file) in your code? Would it be a problem to require people to declare the private first. We can add the @ character automatically in the compiler. We already have support for that.
If it is a problem to require people to declare the variable first then it would also be possible to mark functions such as ADatabase() with a special attribute in the runtime, so the compiler "knows" that this is a function that may create a new local and then it can automatically generate a private (or local) declaration at compile time.
Robert
From what we have seen the FoxPro arrays are one dimensional arrays that also support a 2 dimensional indexes.
You can declare an array like this
Code: Select all
Dimension myArray(2,2)
myArray(1,1) = 1
myArray(1,2) = 2
myArray(2,1) = 3
myArray(2,2) = 4
myArray(4) and see the value 4.
or
Redimension the array to
Code: Select all
Dimension myArray(4)
We have this working.
However this works quite different from the array support that we already have in the system, which is based on the Clipper array support (sometimes also called Ragged Arrays) where each array is in fact a single dimensional array, but the elements of the array can also be arrays, which allows unlimited nested arrays. This array support is also available in Visual Objects, Vulcan and Xbase++.
The questions that we have are:
1) In the FoxPro dialect should there be both the FoxPro compatible arrays (for example declared with the Dimension keyword) and Clipper compatible (Ragged) arrays ? Or should we map the ARRAY keyword in the FoxPro dialect to the special FoxPro array type?
2) There are many functions in the FoxPro runtime that take an not declared, unitialized array and fill the array. See for example this code from the VFP helpfile:
Code: Select all
Set PATH TO (HOME(2) + 'data') && Sets path to database
Open Database testdata && Opens the database
? ADatabases(gaDatabase) && Creates an array of open databases
In most other XBase dialects you would write it like this
Code: Select all
LOCAL gaDatabase && declare the array (could also be PRIVATE gaDatabase)
? ADatabases(@gaDatabase) && pass the array by reference so ADatabases() can create it
Code: Select all
LOCAL gaDatabase && declare the array (could also be PRIVATE gaDatabase)
gaDatabase = ADatabases() && then the array gets returned, but we loose the numeric return value
If it is a problem to require people to declare the variable first then it would also be possible to mark functions such as ADatabase() with a special attribute in the runtime, so the compiler "knows" that this is a function that may create a new local and then it can automatically generate a private (or local) declaration at compile time.
Robert