[fpc-pascal] Usage of Generics in FPC

Jonas Maebe jonas.maebe at elis.ugent.be
Thu Feb 12 11:43:27 CET 2009


On 12 Feb 2009, at 11:26, Graeme Geldenhuys wrote:

> I was given the following Delphi link to help explain generics.
>  http://sjrd.developpez.com/delphi/tutoriel/generics/
>
> I noticed very early on that FPC has a very different sytax to Delphi.
> I guess that's because FPC implemented generics first?

Yes.

> Are there plans to change the syntax
> to match Delphi?

I don't know. But at this time, further generics development appears  
to be at a standstill anyway (Peter has little time for FPC  
development nowadays).

> Anyway, I found the "fgl.pp" unit which contains a generic list:
> TFPGList class. Does FPC include any other classes for use with
> generics?

fgl is the only unit with generics classes shipped with FPC at this  
time.

> Why can't I do the following:
>
> procedure WriteSquares(AMax: Integer);
> var
>  List: specialize TFPGList<integer>;
> begin
>  List := TFPGList<integer>.Create;
>
>
> ...instead I have to ALWAYS declare a type first....
>
>
> type
>  TIntList = specialize TFPGList<Integer>;
>
> procedure WriteSquares(AMax: Integer);
> var
>  List: TIntList;
> begin
>  List := TIntList.Create;

Probably to simplify the parser (to reduce ambiguities with the parser  
has to decide whether you want to perform a comparison or instantiate  
a generic). There may even be undecidable cases otherwise.


Jonas



More information about the fpc-pascal mailing list