[fpc-pascal] FPC's generics

Bisma Jayadi bisma at brawijaya.ac.id
Wed Jun 13 13:35:54 CEST 2007

Hi all,

FPC uses 2 keywords for generics: "generic" for generic definition block, and 
"specialize" for generic type implementation. I think the "generic" keyword is 
quite redundant, useless, and too verbose since generics already use pair of <> 
to define a generics type. Generics definition should be enough described using 
the pair of <> only without "generic" keyword.

The example below should be very obvious to the compiler:

(*** begin of example ***)

   TRegularIntegerArray: array[0..100] of integer;
   TGenericArray<T>: array[0..100] of T;

   IntegerArrayFromGeneric = specialize TGenericArray<integer>;

(*** end of example ***)

Or, if we MUST use "generic" keyword to help compiler parse the code, also make 
the syntax less cryptic, I suggest using the example below:

(*** begin of example ***)

   TList = generic class(TObject)
     type public
        TCompareFunc = function(const Item1, Item2: T): Integer;
     var public
       data : T;
     procedure Add(item: T);
     procedure Sort(compare: TCompareFunc);
   end of T;

   TGenericArray: generic array[0..100] of T;

   PointerListFromGeneric = specialize TList for Pointer;
   IntegerArrayFromGeneric = specialize TGenericArray for Integer;

(*** end of example ***)

Though I agree that a generic MUST have a clear structure definition (in type 
section) before it's being used (in var section), since generic is all about 
type definition, also for ease of readability.

Any comments?


has Bee.ography at:

More information about the fpc-pascal mailing list