[fpc-devel] Templates / Generics

Peter Vreman peter at freepascal.org
Mon Nov 7 12:54:23 CET 2005

>> - instantiation will be only possible in declaration blocks, not in code
>> blocks:
>> possible:
>> var
>>   mylist : TList<integer>;
>> const
>>   mylist : TList<integer> = nil;
>> type
>>   mylist = TList<integer>;
>> forbidden:
>> procedure p(mylist : TList<integer>);
>> begin
>>   ...
>>   mylist:=TList<integer>.create;
>>   ...
>> end;
> This seems like a smart and sufficient solution to avoid the problem of
> parsing < tokens in code blocks.
> On the other hand, programmers will like it (a lot) more if they don't
> need to separately define a type for every generic instantiation. Is the
> token-lookahead approach proposed elsewhere in this thread not a
> sufficient solution? If it is not very easy, or if we are quite unsure
> about this for now, perhaps we can postpone the implementation of
> in-code(block) generic instantiation to a later time and first implement
> generics as above.

The token-lookahead is a hack and will create more problems and
performance loss in a critical part of the compiler.

The restriction of type blocks only is not strange at all, Delphi allows
'class of' is also only in type blocks

More information about the fpc-devel mailing list