Hi Guys,
Phew, a lot of ideas for how to deal with arrays in about of functions! Right now the AppGameKit compiler handles arrays pretty much like DBP and I am using this as a grounding post for any new fangled ideas thrown at it
I'm not too happy about adding arrays within user types, pointer types, special operators, memory commands, complex array symbolism or departing too far from how the DBP array system functioned right now.
So right now an array is created like this:
Dim myarray[100] As Integer
And accessed like so:
myarray[50]=123
Having read 'most' of the posts, it seems there is a strong desire to enable modular tasks by passing all or some of the array into a function by reference and/or by value.
Just a heads up that in order to promise universal compatibility with any device with AppGameKit, I have instructed the compiler to reject locally defined arrays within user functions to preserve stack memory, which some devices might have precious little of. This means we don't need arrays passed by value (which is not a great idea for performance apps, i.e. all apps). This leaves pass by reference, which is also not required as all arrays by virtue of not having any local arrays are entirely global. This means all arrays can be accessed immediately without them being passed into functions and thus producing a faster program. Agreed, yes, no?
One area I could look at is passing variables (standard and UDT) by reference, so you can do something like this:
Type LeeType
A B C
EntType
Dim Lee[50] as LeeType
For N=1 To 100
MyFunc(Lee[N])
Next N
End
Function MyFunc(T As LeeType Ref)
T.A = T.B
EndFunction
Essentially without the 'Ref' keyword it would be a typical pass by value which works in DBP right now, but the Ref keyword instructs the calling command to only pass the UDT pointer and instructs the user function to handle the T as a pointer to the data, rather than the data itself. In this case, you can see the clear performance advantages, especially if the UDT was a large one.
Sorry to reduce what must be a huge amount of discussion to the statement, let's add a 'Ref' keyword, but I wanted to get some reaction on taking a popular request and running with it. I thought about 'it'll be a cold day in hell before I implement that pile', but figured you needed something more constructive after waiting over a month!
I may also be tempted to add this command:
Dim Lee[50] As Integer
Dim Fred[100] As Integer
CopyArray ( Fred[], Lee[] )
Essentially the compiler would understand this as 'copy as much of Lee into Fred as you can without creating a memory overrun. Variations on this theme could be:
CopyArray ( Fred[], iToPos, Lee[], iFromPos, iSize )
The reason I propose this over lots of squiggles is that symbolic meaning is very tough to read when you don't know the language, and we want AppGameKit to be very readable (like the original BASIC). Coders will understand a command approach. I also feel that because we are using a VM/Interpreter, it is not recommended to create a large loop to copy this data one element at a time for performance reasons. The above command would resolve to a single memcpy command, and providing the two arrays are sensibly paired to types, will be amazingly fast indeed. I am not too keen on an 'intelegent' copy which trawls UDT fields for likely things to copy as this hides functionality under the hood, requiring a healthy user manual to unravel what is going on.
Whether we denote the array reference as 'Fred[]', or just 'Fred' is open for debate but I leaned towards the [] to clearly show this is an array, and used very deliberately. Emotionally though, without the brackets, the code looks much cleaner and a little nicer to read.
If I can get a consensus on these two issues (A) adding 'Ref' and (B) adding CopyArray and whether these satisfy many (er, two) of the functional additions you would like to see in AGK. Personally I can see myself using both of these quite a lot as they're very easy to incorporate into my existing coding habits
So for me;
A=YES
B=YES
I drink tea, and in my spare time I write software.