Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!mit-eddie!genrad!decvax!decwrl!labrea!navajo!ali From: ali@navajo.UUCP Newsgroups: comp.lang.pascal Subject: Re: Help on conformant arrays wanted... Message-ID: <1402@navajo.STANFORD.EDU> Date: Sat, 21-Feb-87 21:45:24 EST Article-I.D.: navajo.1402 Posted: Sat Feb 21 21:45:24 1987 Date-Received: Mon, 23-Feb-87 05:46:44 EST References: <1040@gould9.UUCP> Reply-To: ali@navajo.UUCP (Ali Ozer) Organization: Stanford University Lines: 48 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