[Seed7-users] Template issue with integer index arrays
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: Simon D. <sim...@ao...> - 2024-08-23 10:57:50
|
I noticed an array on the website with a non-integer index: Something like this: var array [char] string : unusual_index is ['0'] ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); So I made a separate two-types templated function to print information on this array: const proc: DECLARE_MY_PRINT_ARRAY(in type: aType1, in type: aType2) is funcbegin const proc: myPrintArray(in array [aType1] aType2: the_array) is func local var aType1: the_index is aType1.value; begin writeln("-----------------------------------------"); writeln("the type of the array index is " & str(aType1) ); writeln("the type of the array elements is " & str(aType2)); writeln("size of the array is " & str(length(the_array))); writeln("minimum index is " & str(minIdx(the_array))); writeln("maximum index is " & str(maxIdx(the_array))); if length(the_array) = 0 then writeln("***** The array is empty ******"); else for key the_index range the_array do writeln(str(the_index) & ": " & str(the_array[the_index])); end for; end if; end func;end func; That works with these statements;DECLARE_MY_PRINT_ARRAY(char, string); var array [char] string : unusual_index is ['0'] ("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"); myPrintArray(unusual_index); But it occurred to me that I should also be able to call that function with standard integer index arrays: var array integer: integer_array is [1] (10, 20, 30, 40,50); DECLARE_MY_PRINT_ARRAY(integer, integer); myPrintArray(integer_array); However, that doesn't work. I am not sure if I am doing something wrong. The interpreter gives errors and they start in array.s7i : *** /c/seed7/lib/idxarray.s7i(107):34: Redeclaration of "[ (val integer: start) ] (ref TST_1: aTuple)" const func arrayType: [ (in indexType: startIndex) ] (in tupleType: arr_tuple) is *** /c/seed7/lib/array.s7i(92):35: Previous declaration of "[ (val integer: start) ] (ref TST_1: aTuple)" const func arrayType: [ (in integer: start) ] (in tupleType: aTuple) is action "ARR_ARRLIT2"; *** /c/seed7/lib/idxarray.s7i(108):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({startIndex ord }) ] arr_tuple }) } failed return arrayType conv ([ord(startIndex)] arr_tuple); *** /c/seed7/lib/idxarray.s7i(110):34: Redeclaration of "[ (val integer: start) ] (val integer: anElement)" const func arrayType: [ (in indexType: startIndex) ] (in baseType: base_elem) is *** /c/seed7/lib/array.s7i(93):35: Previous declaration of "[ (val integer: start) ] (val integer: anElement)" const func arrayType: [ (in integer: start) ] (in baseType: anElement) is action "ARR_BASELIT2"; *** /c/seed7/lib/idxarray.s7i(111):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({startIndex ord }) ] base_elem }) } failed return arrayType conv ([ord(startIndex)] base_elem); *** /c/seed7/lib/idxarray.s7i(221):52: Match for {arrayType conv func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ INT_ICONV1({integer: <INTOBJECT> ({integer . first }) ord }) ] ARR_CONV({tupleType conv anArray }) }) } failed anArray := arrayType conv ([ord(indexType.first)] (tupleType conv anArray)); *** /c/seed7/lib/idxarray.s7i(216):32: Declaration of "(attr type) times (val integer: base_value)" failed const func arrayType: (attr indexType) times (in baseType: base_value) is func *** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(78):52: Match for {integer_array ::= func *ANONYM_TYPE* : <DECLAREDOBJECT> ({[ 1 ] ARR_EXTEND({ARR_EXTEND({ARR_EXTEND( *** details suppressed *** ) , 40 }) , 50 }) }) } failedend func;---------^*** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(66):32: Declaration of "integer_array" failed var array integer: integer_array is [1] (10, 20, 30, 40,50); *** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(73):52: Match for {integer_array myPrintArray } failed myPrintArray(integer_array); *** /c/Users/sdash/OneDrive/code/Seed7/Exploring/my_print_array.sd7(64):32: Declaration of "main" failedconst proc: main is func Simon |