Re: Generic type declaration example versus manual.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Generic type declaration example versus manual.

Pascal-55
Hello Anthony.

Thanks for your proposal.
I'm a bit surprised of Delphi chosen syntax because  
"TList<T>=class ..." breaks Pascal usual type declaration
"Id=type;" and "<T>=" may be confused with greater or equal operator.

Have you some documentation available on Internet?
The one I found is Delphi Object Pascal Language Guide, version 7, 2002.
http://docs.codegear.com/products/rad_studio/delphi7/ 
D7_DevelopersGuide.pdf
Generic types are not described in it ;-(

Best, Pascal.
http://blady.pagesperso-orange.fr




Le 22 nov. 09 à 12:00, [hidden email] a écrit :

> From: Anthony Walter <[hidden email]>
> Subject: Re: [fpc-pascal] Generic type declaration example versus
> manual.
>
> I haven't used generics in FPC, but really have to ask, is they
> keyword generic really necessary? Shouldn't generics be declared like
> this:
>
> type
>   TList<T> = class
>   private
>      ...
>   public
>     function Add: T;
>     procedure Remove(Item: T);
>     property Item[Index: Integer]: T read Get write Put; default;
>   end;
>
> I believe this makes the most sense, and it's also how they are
> declared in Delphi.
>
> It would be a real shame to create more Delphi incompatibilities.



_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Generic type declaration example versus manual.

Jonas Maebe-2

On 22 Nov 2009, at 21:17, Pascal wrote:

> Have you some documentation available on Internet?
> The one I found is Delphi Object Pascal Language Guide, version 7, 2002.
> http://docs.codegear.com/products/rad_studio/delphi7/D7_DevelopersGuide.pdf
> Generic types are not described in it ;-(

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/pdf/devcommon.pdf


Jonas_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Generic type declaration example versus manual.

Anthony Walter-3
As a follow up, here are a few generic type declaration examples
lifted directly out of the CodeGear pdf Jonas was thoughtful enough to
link:

*Please Note* These examples do not include generic constraints which
I believe are needed to work effectively with generics. Generic
constraints can be found in the referenced pdf section "3.1.3.3.5
Constraints in Generics" page 626

type
 TFoo1<T> = class(TBar) // Actual type
 end;

 TFoo2<T> = class(TBar2<T>) // Open constructed type
 end;

 TFoo3<T> = class(TBar3<Integer>) // Closed constructed type
 end;

 TMyProc<T> = procedure(Param: T); // procedure type

 TMyProc2<Y> = procedure(Param1, Param2: Y) of object;  // event type

 TRecord<T> = record
   FData: T;
 end;

 IAncestor<T> = interface
   function GetRecord: TRecord<T>;
 end;

 IFoo<T> = interface(IAncestor<T>)
   procedure AMethod(Param: T);
 end;

 TFoo<T> = class(TObject, IFoo<T>)
   FField: TRecord<T>;
   procedure AMethod(Param: T);
   function GetRecord: TRecord<T>;
 end;
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Generic type declaration example versus manual.

Anthony Walter-3
In reply to this post by Jonas Maebe-2
I improperly replied. Let me try that again.....

As a follow up, here are a few generic type declaration examples
lifted directly out of the CodeGear pdf Jonas was thoughtful enough to
link:

*Please Note* These examples do not include generic constraints which
I believe are needed to work effectively with generics. Generic
constraints can be found in the referenced pdf section "3.1.3.3.5
Constraints in Generics" page 626

type
 TFoo1<T> = class(TBar) // Actual type
 end;

 TFoo2<T> = class(TBar2<T>) // Open constructed type
 end;

 TFoo3<T> = class(TBar3<Integer>) // Closed constructed type
 end;

 TMyProc<T> = procedure(Param: T); // procedure type

 TMyProc2<Y> = procedure(Param1, Param2: Y) of object;  // event type

 TRecord<T> = record
  FData: T;
 end;

 IAncestor<T> = interface
  function GetRecord: TRecord<T>;
 end;

 IFoo<T> = interface(IAncestor<T>)
  procedure AMethod(Param: T);
 end;

 TFoo<T> = class(TObject, IFoo<T>)
  FField: TRecord<T>;
  procedure AMethod(Param: T);
  function GetRecord: TRecord<T>;
 end;
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal