naparst@cartan.Berkeley.EDU (Harold Naparst) (12/20/87)
I don't quite understand conformable array parameters. 1) How do you pass part of an array, like in fortran ? The fortran code below passes the segment a(5),a(6),a(7) (or even more, I know). What is the analogy in Pascal. I tried to get it from Cooper's books, but it wasn't clear. real a(10) call sub(a(5),3) subroutine sub(a,n) real a(n) ..... 2) Probably most importantly, are conformable arrays standard ? Cooper says something about Level 1 and Level 2 Pascal. What finally happened ? Harold Naparst (415)-548-4652 UUCP {tektronix,dual,sun,ihnp4,decvax}!ucbvax!cartan!naparst New style naparst@cartan.berkeley.edu ARPA | CSNET naparst%cartan@berkeley.edu -- Harold Naparst (415)-548-4652 UUCP {tektronix,dual,sun,ihnp4,decvax}!ucbvax!cartan!naparst New style naparst@cartan.berkeley.edu ARPA | CSNET naparst%cartan@berkeley.edu
victor@cs.vu.nl (L. Victor Allis) (12/21/87)
In article <1472@cartan.Berkeley.EDU> naparst@cartan.Berkeley.EDU (Harold Naparst) writes: >I don't quite understand conformable array parameters. > > 1) How do you pass part of an array, like in fortran ? > 2) Probably most importantly, are conformable arrays standard ? Cooper > says something about Level 1 and Level 2 Pascal. What finally happened ? 1) It is not possible to pass parts of array's in Pascal, not even using conformant array paramaters. In Pascal one has to specify exactly on what type of parameter the function or procedure is going to work. Sometimes you want to perform the same operations on similar, but different typed variables. Suppose you use at least two different real array's. You want to know the average of the elements in the array's. It would be boring to write two similar functions to perform this actions. This is the place where conformant array parameters come in: function Average(SomeArray : array[Lower..Upper: integer] of real): real; var i : integer; Sum : real; begin Sum := 0.0; for i := Lower to Upper do Sum := Sum + SomeArray[i]; Average := Sum / (Upper - Lower + 1) end; This function can be called with each actual parameter which is a real arry, with index a subrange of integer, instead of only one type of array. This is the only place in Pascal where structure-equivalence is important instead of name-equivalence. 2) In fact it is called level 0 Pascal (no conformant array parameters) and level 1 Pascal (with conformant array parameters). Both levels are defined in the Pascal ISO-standard. I can recommend the Pascal User Manual and Report by Jensen and Wirth. This book will answer all your questions. Victor Allis. Vrije Universiteit of Amsterdam. The Netherlands.
shankar@hpclscu.HP.COM (Shankar Unni) (12/22/87)
> > 2) Probably most importantly, are conformable arrays standard ? Cooper > says something about Level 1 and Level 2 Pascal. What finally happened ? > Yes, there is an ISO standard for pascal that has things called "Conformant Arrays". The syntax is as follows: TYPE myarr = array [1..5] of mytype; (* say *) VAR myvar : myarr; PROCEDURE proc (VAR myparm : ARRAY [lowbnd..highbnd : INTEGER] of mytype); BEGIN ... (* you can access "lowbnd" and "highbnd" as read-only variables here, for example as loop indices *) ... END; ... BEGIN proc (myvar); (* this passes myvar as the actual array, and 1 and 5 as lowbnd and highbnd, respectively *) END; > > 1) How do you pass part of an array, like in fortran ? The fortran > code below passes the segment a(5),a(6),a(7) (or even more, I know). > What is the analogy in Pascal. I tried to get it from Cooper's books, > but it wasn't clear. > > real a(10) > call sub(a(5),3) > > subroutine sub(a,n) > real a(n) > ..... As far as I know, there is no good, clean way to do exactly this in Pascal. ----------------------------------------------------------------------------- Shankar Unni Unix Mail: shankar@hpclscu , shankar%hpclscu@hpda HPMAIL: SHANKAR UNNI/HPUNIX/UX Telnet: 1-447-5797 -----------------------------------------------------------------------------