The case for... and against.. variable tables #254
samiam95124
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The case for... and against.. variable tables
What is a variable table? Its a language proposal for Pascaline that blatantly rips off, errr, parallels the feature in the C language, only (of course) type safe.
Both string, and array of string, are arrays with an unspecified number of elements. The idea is that there is no reason a fixed object could not get its number of index elements from the actual constant table appearing in the fixed statement. Thus it is the equivalent of:
fixed stable: array [1..3] of packed array [1..11] of char;
Now let's get really wild and crazy:
Ok, this one is the same, but the strings are no longer padded out to 11 spaces as before. Basically we never promised that all of the elements would be equal in length, and indeed, there is no reason why they have to all be equal. In this case, max(stable[1]) and max(stable[2]) would be different (9 and 11 characters respectively).
Now what would you pay?
For the first example, the compiler can find the length of the first element (a string) and know the size of all strings in the array. The compiler can't know the major index of the array (how many strings) because it must parse them all to find that out.
The second one is more complex. The compiler must parse the entire constant table to find the length of all elements.
So how is the second array constructed in the runtime? In C this is done by declaring the array as an array of character pointers. Thus the strings are actually stored elsewhere. The array that holds them is actually an array of character pointers. And that is not far from what Pascaline would have to do. Basically it would be an array of pointers to strings, with each element containing the length of the string it contains.
Ok, why?
Well, you could say it is case of C envy. However, this does give you a construct equivalent to the way C does it, and a very convenient way to create string tables by the way[1]. Also, in case of variable length string elements, the true mechanisim of how it is done is hidden from the programmer.
And yes, it is type safe.
[1] Or a table of anything, by the way. It works on arrays of any base type, including multidimensional.
Beta Was this translation helpful? Give feedback.
All reactions