[comp.lang.pascal] Help on conformant arrays wanted...

joel@gould9.UUCP (02/21/87)

I was reading the latest edition of the Pascal report, trying to figure
out what the ISO Level 1 spec is, when I came across the famous
conformant arrays.

It gets about 2 pages of incomprehensible prose.  The closest I
could come is that a conformant array is a parameter in which
the type of the element is fixed, but the upper and lower
bounds are implicit parameters.

If anyone understands this, could they clue me in?
-- 
	Joel West			     MCI Mail: 282-8879
	Western Software Technology, POB 2733, Vista, CA  92083
	{cbosgd, ihnp4, pyramid, sdcsvax, ucla-cs} !gould9!joel
	joel%gould9.uucp@NOSC.ARPA

ali@navajo.UUCP (02/22/87)

In article <1040@gould9.UUCP> joel@gould9.UUCP (Joel West) writes:
>...The closest I could come is that a conformant array is a parameter 
>in which the type of the element is fixed, but the upper and lower
>bounds are implicit parameters.
> Joel West

Conformant arrays provide a way with which procedures do not have to know
about the size of the array they are getting. Consider the following
declaration:

function StrLen (s: packed array [lo..hi: integer] of char): integer;

StrLen expects to receive a packed array of characters, indexed by integers.
Thus all of the following are legal calls:

var s1: packed array [1..6] of char;
    
n := StrLen (s1);   
n := StrLen ('foo');
n := StrLen ('');

When you call StrLen with s1, s will become a packed array of 6 characters,
and lo will be set to 1, and hi will be set to 6. When you call StrLen
with 'foo', s will become 'foo' and lo and hi will be 1 and 3, respectively.
In the last case, lo will be 1 and hi will be 0.

Note that conformant arrays are most useful with packed arrays of characters.
(And that's why my 3 examples include them...). Also note that when you
pass in a constant string (ie, a literal), the lower bound automatically
gets 1 --- This is a special case (as in no other instance can you pass in
a constant array).

Another example of conformant arrays could be:

procedure ClearCharCount (var foo : array [low..high: char] of integer);
var ch : char;
begin
  for ch := low to high do foo[ch] := 0;
end;

Then you could call the above procedure with all of the following arrays:

var lowercase: array ['a'..'z'] of integer;
    uppercase: array ['A'..'Z'] of integer;
    all      : array [' '..'~'] of integer;


Ali Ozer, ali@navajo.stanford.edu

dik@mcvax.UUCP (02/24/87)

In article <1402@navajo.STANFORD.EDU> ali@navajo.UUCP (Ali Ozer) writes:
>Note that conformant arrays are most useful with packed arrays of characters.

Nope (from my viewpoint), conformant arrays make it possible, for the first
time, to write large numerical libraries.
-- 
dik t. winter, cwi, amsterdam, nederland
INTERNET   : dik@cwi.nl
BITNET/EARN: dik@mcvax

bobd@dshovax.UUCP (02/27/87)

In article <333@zuring.mcvax.cwi.nl> dik@zuring.UUCP (Dik T. Winter) writes:
>In article <1402@navajo.STANFORD.EDU> ali@navajo.UUCP (Ali Ozer) writes:
>>Note that conformant arrays are most useful with packed arrays of characters.
>
>Nope (from my viewpoint), conformant arrays make it possible, for the first
>time, to write large numerical libraries.
>-- 
>dik t. winter, cwi, amsterdam, nederland

Note that the draft proposed Extended Pascal standard does quite a bit in
this area. It has a more general form of conformable arrays called schemata,
which are essentially parameterized types. Schemata are not restricted to
parameter lists, and can be used in variable declarations, for variables
created by "new", and form the basis of the string feature.

{After several tries, I have been unable to get through to Ali Ozer. Since our
news feed was down when the original article came through, would someone be
kind enough to forward me a copy of it and any related articles? Thanks in
advance.}

				Bob Dietrich
				Intel Corporation, Hillsboro, Oregon
				(503) 681-2092
		usenet:		tektronix!reed!omssw2!dshovax!bobd