|
|
Bruno Cabasson <bru### [at] yahoofr> wrote:
> > extend() - not sure how far you will be able to .. bend SDL , but
> think that
> > an important macro like extend should be "general". clipka's advice
> wrt arrays
> > was (paraphrasing) "if you know the #elements in advance, declare the
> array
> > sized"; however, if I were to:
> > #declare A = array [2] {"a","b"};
> > #declare B = array [2] {"c","d"};
> > extend(A,B)
> > I'd get: "Parse Error: Array subscript out of range".
> >
>
> ===> You are correct. The use of some PROOF features may (and will)
> imply some restrictions. But that's highly secondary for me. In this
> particular case, I don't know if Sdl can detect if the array is of fixed
> sized. Please, enlighten me.
I don't think it can tell in a non-error triggering way.
Looking at your code,
#macro extend(arr, extension_arr)
// We cannot know whether an array is "array" or "array mixed".
// So we let the aprser generate an error if elements are of incompatible
types.
#local start = dimension_size(arr, 1);
#for (i, 0, dimension_size(extension_arr, 1) - 1)
#local arr[start + i] = extension_arr[i];
#end
#end
I think all you have to do is determine the size of both arrays, create a
temporary array of either dynamic size, or big enough to hold all the elements
of both, fill that array, and then declare the original array identifier name to
now be the new temporary array.
That would also let you get around the mixed array error, by making temporary
array a mixed type.
Post a reply to this message
|
|