Thanks to all ! The variable GPC_UNIT_PATH works very well and, despite the wise advice of Frank, I've included the current directory in my PATH (I'm strictly and for ever a single-user). The statement "export all" is convenient to export operators, the only joke is that we must use the full header of the operator (params and return name) in the implementation part, unlike the forward style of other routines.
Now, I was puzzled by the comportment of the Borland functions Low and High. Writing the small test :
program testarraypar ;
procedure writeRange (T : array of integer) ; begin WriteLn('param range : ', Low(T), '..', High(T)) ; end ;
var T : array [1..10] of integer ;
begin WriteLn('arg range : ', Low(T), '..', High(T)) ; writeRange(T) ; WriteLn('arg range : ', Low(T[2..9]), '..', High(T[2..9])) ; writeRange(T[2..9]) ; end.
the running gives :
arg range : 1..10 param range : 0..9 arg range : 2..9 param range : 0..7
That's not fair ! And with such a comportment, the parameter type "array of integer" becomes almost useless : iterative sorting routines do their job but not the linear search nor the binary one (except with stupid things like "return index + Low(T)" that I refuse to teach with beginners). Knows someone an other way to access the bounds of an "array of integer" ? Thanks in advance, Dominique
Dominique Thillaud wrote:
The statement "export all" is convenient to export operators, the only joke is that we must use the full header of the operator (params and return name) in the implementation part, unlike the forward style of other routines.
This is necessary because operators can be (and usually are) overloaded, so the formal parameters are needed to recognize the operator.
Now, I was puzzled by the comportment of the Borland functions Low and High. Writing the small test :
program testarraypar ;
procedure writeRange (T : array of integer) ; begin WriteLn('param range : ', Low(T), '..', High(T)) ; end ;
var T : array [1..10] of integer ;
begin WriteLn('arg range : ', Low(T), '..', High(T)) ; writeRange(T) ; WriteLn('arg range : ', Low(T[2..9]), '..', High(T[2..9])) ; writeRange(T[2..9]) ; end.
the running gives :
arg range : 1..10 param range : 0..9 arg range : 2..9 param range : 0..7
That's not fair !
Yes, it's a Borland feature. ;-)
And with such a comportment, the parameter type "array of integer" becomes almost useless : iterative sorting routines do their job but not the linear search nor the binary one (except with stupid things like "return index + Low(T)" that I refuse to teach with beginners).
This won't work, anyway, since `Low (T)' (in the routine) is always 0 with BP open arrays.
Knows someone an other way to access the bounds of an "array of integer" ?
You can use (standard Pascal) conformant arrays instead:
procedure WriteRange (T: array [m .. n: Integer] of Integer);
Then m and n (and also Low (T) and High (T)) will contain the actual bounds.
Frank
That works well. Thanks again !
Le mercredi, 10 sep 2003, à 19:56 Europe/Paris, Frank Heckenbach a écrit :
Dominique Thillaud wrote:
The statement "export all" is convenient to export operators, the only joke is that we must use the full header of the operator (params and return name) in the implementation part, unlike the forward style of other routines.
This is necessary because operators can be (and usually are) overloaded, so the formal parameters are needed to recognize the operator.
Now, I was puzzled by the comportment of the Borland functions Low and High. Writing the small test :
program testarraypar ;
procedure writeRange (T : array of integer) ; begin WriteLn('param range : ', Low(T), '..', High(T)) ; end ;
var T : array [1..10] of integer ;
begin WriteLn('arg range : ', Low(T), '..', High(T)) ; writeRange(T) ; WriteLn('arg range : ', Low(T[2..9]), '..', High(T[2..9])) ; writeRange(T[2..9]) ; end.
the running gives :
arg range : 1..10 param range : 0..9 arg range : 2..9 param range : 0..7
That's not fair !
Yes, it's a Borland feature. ;-)
And with such a comportment, the parameter type "array of integer" becomes almost useless : iterative sorting routines do their job but not the linear search nor the binary one (except with stupid things like "return index + Low(T)" that I refuse to teach with beginners).
This won't work, anyway, since `Low (T)' (in the routine) is always 0 with BP open arrays.
Knows someone an other way to access the bounds of an "array of integer" ?
You can use (standard Pascal) conformant arrays instead:
procedure WriteRange (T: array [m .. n: Integer] of Integer);
Then m and n (and also Low (T) and High (T)) will contain the actual bounds.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html GPC download signing key: 51FF C1F0 1A77 C6C2 4482 4DDC 117A 9773 7F88 1707