Forum > Beginners

Array type in procedure

(1/2) > >>

Jackr:
Hi!

I cannot compile procedures including array as variable type.
For instance, the procedure below does not work:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure imatout(var m : array[lo1..hi1:integer,lo2..hi2:integer]                                 of integer;  row,col : oneton;  marge : integer);              var   i,j  :  oneton;                                                                  a,s  :  integer;                                                                 sign :  boolean;                                                           begin                                                                               s:= marge + 1;                                                                   for i:= 1 to row do begin                                                           sign:= false;                                                                    for j:= 1 to col do if m[i,j] <> 0 then begin                                       a:= abs(m[i,j]);                                                                 if m[i,j] < 0 then ritchar('-',marge,s)                                          else if sign  then ritchar('+',marge,s);                                         if a > 1 then begin                                                                 intgout(a,marge,s);                                                              ritchar('*',marge,s);                                                         end;                                                                             if s > pagewidth-3 then s:= indent(marge);                                       write('e',secondchar(j));  s:= s + 2;                                            sign:= true;                                                                  end;                                                                             if i < row then ritchar(',',marge,s) else write('.');                         end;                                                                          end;  
How to change the code array[lo1..hi1:integer,lo2..hi2:integer] ?

Thanks

Jackr

howardpc:
Declare the types you want to use outside the procedure, not inside its parameters.
Something like

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type   TRange1 = lo1..hi1;  TRange2 = lo2..hi2;  TRange12Array = array[TRange1, TRange2] of integer;   ToneTon = 0..100;   procedure imatout(var m: TRange12Array; row, col: ToneTon; marge: integer);    

Leledumbo:
First:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---array[lo1..hi1:integer,lo2..hi2:integer] of integeris not a valid multidimensional array declaration even when not in parameters.

Second, FPC doesn't (or hasn't) implemented Extended Pascal's type schema which allows dynamically sized multidimensional arrays to be passed as parameters, even statically sized arrays are NOT allowed to be declared as parameter type (you must define a type for it and use that type's name as parameter type). Instead, it follows Delphi's dynamic array and open array implementation to solve cases like this.

Jackr:
Hi!

Thank you howardpc and Leledumbo for your replies.

To Leledumbo: Ok, arrays are not dynamically sized in FPC. And thus, can we say that it does not implement the extended PASCAL ISO 10206? Could the two others compilers "GNU PAscal" or "Prospero PASCAL" solve this issue?

To howardpc: your solution works. But, I must confess that the procedure I presented in this post is exerpted from an old program written in PASCAL 6000 in 1987... And, I try to modify the code for compilation with FPC. Thus, if your modification works fine independantly of the environement code of this old program, it does not with the other parts of the code.

The program can be downloaded at this url:

http://cpc.cs.qub.ac.uk/summaries/AALB_v1_0.html


Do you have suggestion for the translation process?

Best regards

Jackr

howardpc:
After some effort and hacking I got the program to compile.
It often bombs out with range check errors or seg faults.
Here is typical output obtained before the first error. I have no idea what it means.

 ********************************************************
 *                                                      *
 *  programme "radical"  -- january 1986 --  version 2  *
 *                                                      *
 *  determine the radical (maximal solvable ideal) and  *
 *  the nil radical (maximal nilpotent ideal) of a lie  *
 *  algebra whose structure constants are either inte-  *
 *  gral or polynomial with integral coefficients.      *
 *                                                      *
 ********************************************************
abcdef
40 80
 
 pagewidth:  80,      power2:  40,      param[1..6]:  .
 
t
 intermediate results will be printed out.   the notation "basis(d1,d2)"
 indicates a basis of the current algebra (of dimension d1+d2), of which
 the first d1 generators form the algebra for the succeeding calculation.
 --------------------------------------------------------------------------------
   1.  another parameter-free example, isomorphic to the above algebra.
 algebra of dimension 5 with commutation relations:
aa.=5
      e1                  e2           e3                   e4           
 -----------------------------------------------------------------------
 e1 \ .                   -e2+e4-e1+e5 -2*e2+2*e4-2*e3-2*e1 e2-e4-e1+e5   
 e2 \ e2-e4+e1-e5         .            -e2+e4+e1-e5         .             
 e3 \ 2*e2-2*e4+2*e3+2*e1 e2-e4-e1+e5  .                    -e2+e4-e1+e5 
 e4 \ -e2+e4+e1-e5        .            e2-e4+e1-e5          .             
 e5 \ -2*e1+2*e5          -e2+e4-e1+e5 -2*e2+2*e4-2*e3-2*e5 e2-e4-e1+e5   
 [e1,e5] = 2*e1-2*e5
 [e2,e5] = e2-e4+e1-e5
 [e3,e5] = 2*e2-2*e4+2*e3+2*e5
 [e4,e5] = -e2+e4+e1-e5
 
 "i3nilrad", depth  3,  dim[l,l] = 3.
             derived alg. & complement:  e1-e5,e2-e4,e3+e5,e2+e4,e1-e3+e5.
             quotienting by b1.
 "iquotient", basis( 4, 1):  e2,e3,e4,e1+e5,e1-e5.
              call "i2nilrad" on factor algebra:
aa.n=4
      e1        e2                   e3         e4                   
 ------------------------------------------------------------------
 e1 \ .         e3-e1                .          -2*e3+2*e1           
 e2 \ -e3+e1    .                    e3-e1      2*e4+4*e2-4*e3+4*e1 
 e3 \ .         -e3+e1               .          2*e3-2*e1           
 e4 \ 2*e3-2*e1 -2*e4-4*e2+4*e3-4*e1 -2*e3+2*e1 .                   
 

Navigation

[0] Message Index

[#] Next page

Go to full version