[fpc-devel] Templates / Generics Syntax

Mattias Gaertner nc-gaertnma at netcologne.de
Thu Nov 3 20:26:36 CET 2005


On Thu, 3 Nov 2005 20:10:35 +0100
Mattias Gaertner <nc-gaertnma at netcologne.de> wrote:

> On Thu, 3 Nov 2005 19:59:40 +0100 (CET)
> Daniƫl Mantione <daniel.mantione at freepascal.org> wrote:
> 
> > 
> > 
> > Op Thu, 3 Nov 2005, schreef Mattias Gaertner:
> > 
> > > 
> > > Here is a proposal of the syntax:
> > > 
> > > type
> > >   TGenericClass<T,F> = class
> > >   public
> > >     procedure Add(Item: T; Flag: F);
> > >   end;
> > 
> > This syntax is almost impossible to implement since in one of your other
> > 
> > mails the symbols to mark the parameters appear in regular source code:
> > 
> > begin
> >   generictypeA<integer>.create
> > end.
> > 
> > It will be very hard for the parser to see the difference in advance 
> > between:
> > 
> >   variable<integer(another_var)
> >   generic_type<integer
> > 
> > Only when the > symbol is parsed the result is known.
> > 
> > Maybe the parser may be able lookup the type first and make a decision 
> > based on that, but it would be in the middle of a recursive expression 
> > parse designed for infix operators.
> > 
> > Also in C++ this sometimes causes trouble where you need to change your 
> > code notation so the compiler eats it. I don't know if this proposal 
> > suffers from this mess, but we should avoid at all cost to import it
> > into  Pascal.
> 
> Right. I didn't think of that.
> 
> What about edged brackets?
> 
> type
>   TGenericClass[T,F] = class
>   public
>     procedure Add(Item: T; Flag: F);
>   end;
> 
> procedure TGenericClass.Add(Item: T; Flag: F);
> // Note: No redundant [T,F] after TGenericClass.
> begin
> end;
> 
> type TListOfComponent = TGenericList[TComponent];
> 
> Analog:
> type TGenericListClass[T] = class of TGenericList[T];
> type PGenericRecord[T] = ^TGenericRecord[T];
> 
> procedure GenericProc[T](Param: T);
> begin
> end;

And a proposal for bounding:

  TGenericClass[T: TComponent] = class end;



Mattias



More information about the fpc-devel mailing list