[fpc-devel] Templates / Generics

Micha Nelissen micha at neli.hopto.org
Mon Nov 7 23:10:52 CET 2005


On Mon, 07 Nov 2005 21:07:42 +0100
Marc Weustink <marc at dommelstein.net> wrote:

> Params are passed to a procedure define like
> 
>    procedure MyProc(param, param, ..)
> 
> Arrays are declared like
> 
>    A: array[0..9] of ...
> 
> And generics.... they are soly defined by the fact that a type has <> in it.

Well generics *are* a kind of "parameterised" type. When you choose types
for the parameters, then the type is fully defined, just like the result of
a not-with-outside-interacting procedure would be when it's parameters are
filled in. When you view it this way, Bram has a point.

I am still a proponent of a keyword btw, which I've documented at wiki:

http://www.freepascal.org/wiki/index.php/Generics#Terms

(just scroll a little upwards). This is because it generalizes better to
function generics, I think that in "Max<T: TSomeType>(Foo: Type): T" the
last T feels "out-of-scope", while it doesn't when you have the generic
keyword because you're defining a "function generic(T) ..."

Of course, these are all minor details compared to actual implementation.

Micha



More information about the fpc-devel mailing list