> 
> This is why FPC has specialize (to emphasis this): only class instances
> having the same specialized generic type are considered being equal:
> type
>    TList1 = specialize TList<Longint>;
>    TList2 = specialize TList<Longint>;
> 
> var
>   l1a,l1b : TList1;
>   l2 : TList2;
> 
> Only l1a and l1b are assignment compatible. This is like records or
> classes are handled in pascal: even records with exactly the same fields
> are not assignment compatible

So, what you are saying is that FPC - with traditional Pascal syntax - only 
supports generics like this:

type
  TList1 = type TList<Longint>; 

Hence, I really don't see any good reason for the new 'specialize' keyword as 
everyone familiar with Pascal/Delphi knows the semantics of the above 
declaration. OTOH 'specialize' is an additional (unfamiliar) keyword and has 
semantics totally unknown to the world. So why not take what's already in the 
language?

> So generics in packages are a non issue for fpc: every package
> specializes the generics created by the units contained in the package
> as it is done currently by a program: the specialization and code
> generation for all generics specialized by a program and its units is
> done during compilation of the program. For packages, it is just done
> during package compilation.

Of course you can export TList1 from a package and consume the type in 
different other packages (which means we need a way of encoding). But you are 
right, since the type has been closed this would not pose a problem.

FPC's generics are, however, very different to all other implementations of 
generics that I know of. And I really(!) hope, that FPC does not do the C++ 
like duck-typing, which could give interesting error messages: think about 
using a package where you do not have the source, and getting an error message 
pointing to the unit in the .dcp.
Hence, I cannot stress often enough that generics found in Delphi W32, .NET, 
Eiffel, Java... are NOT C++ templates. And you should emphasize this in 
http://www.freepascal.org/docs-html/ref/refse41.html#x93-1000008.1. The concept 
of generics found in all modern languages (except C++) does not come from C++ 
and - see C# 4.0/.NET - is quite advanced.

But enough about generics, back to packages: I'll start doing an implementation 
for the non-generic part first. Let's see how this goes. Since I need to read 
into fpc source (and do this in my spare time), don't expect any spectacular 
results soon. In case there are more people interested in implementing this, 
some branch in the repo would be needed - if I am the only one, I will do this 
locally on my disk.

Cheers,
 Willi


-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 Euro/mtl.!*
http://portal.gmx.net/de/go/dsl
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply via email to