type MyArray(count: Integer) = array[1..count] of Integer; var p: ^MyArray; begin New(p,10); p^[1..5] := p^[2..6]; end.
However, this might be difficult to implement, because which type should an array slice have? For string slices, we have the generic string-type which is always compatible. For other arrays, there are no generic types, and two arrays [1 .. 5] and [2 .. 6] are normally not compatible. I suppose the Borland solution would be to shift slices (if they had them) to base 0, as they do with arrays in several other contexts, but I don't really like this (as it can be very confusing and a trap to the unknowing, as are their "open arrays"). So if we can find a more elegant solution, without doing away with type-checking at all, of course, it could be worth changing it in GPC ...
I guess the most elegant solution would be to say that p[1..5] is a subarray of MyArray, and that such a type is assignment compatible with MyArray and other subarrays, and that you then need a runtime check to test that the length of the subarrays match (or the subarray matches the total length of MyArray) (unless the values are all compile time constants and the check can be done at runtime, which is not guaranteed).
But it would introduce a bunch of new things (the concept of a subarray type, and runtime checks for assignment compatibility), and whether that is worth the advantage of doing
p^[1..5] := p^[2..6];
instead of
Assert( 6-2+1 = 5-1+1 ); Move( p^[2], p^[1], (5-1+1) * SizeOf(p^[2]) );
I don't know.
While I'm at it, is there any better way to zero part of such an
array than:
FillChar( p^[3], 4 * SizeOf(p^[3]), 0 );
I suppose a simple for-loop is not acceptable for some reason?
No particular reason, except for the extra lines, extra index variable and definition, and the I find the for loop is less clearly an array assignment that a Move/Zero. Conceptually to me, the for loop is indexing over the elements of the array, where really I want to reset the array - its a subtle distinction that probably doesn't concern others).
And further while I'm at it, I looked at the docs for MoveLeft et al, and they are all under construction. Would it be worth while setting up a wiki for the docs?
I doubt it.
I won't stop you if you like. (Only I won't do any serious setup effort anymore ...)
I know the docs are all tied in with the make system, and there might be some loss with regard to automation of that,
Ok, I guess then the next question is whether any folks think they would contribute to the docs if they were available in a wiki form. If so, speak up, otherwise I agree with Frank that there is little reason to make the effort.
Enjoy, Peter.