[fpc-devel] Templates / Generics Syntax

Florian Klaempfl florian at freepascal.org
Fri Nov 4 10:59:47 CET 2005


Daniël Mantione 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:

I wouldn't allow specialization in the procedure body. That's unpascalish, you
can' do
((^char)(p))^:=#0;
but you need to define a pchar in a type section and do
pchar(p)^:=#0;

By forbidding that we can come back to the < ... >.

> 
>   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.
> 
> Daniël
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel




More information about the fpc-devel mailing list