What is the state and future plans of generics?
I only found the wiki page
http://wiki.lazarus.freepascal.org/Generics
which does not even mention the current syntax.
Mattias

Mailing lists / fpc-devel / 2007-08
15 messages · 6 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
What is the state and future plans of generics?
I only found the wiki page
http://wiki.lazarus.freepascal.org/Generics
which does not even mention the current syntax.
Mattias
The current syntax is descibed in the docs, reference manual. There is a chapter about generics. Feel free to comment on it; any omissions, I'll be glad to fill them in (as far as I can, I don't use generics myself).
Michael.
Images are so big that is difficult to follow the diagrams..
Jesus Reyes A.
____________________________________________________________________________________ ¡Sé un mejor besador!
Comparte todo lo que sabes sobre besos.
http://mx.yahoo.com/promos/mejorbesador.html
sorry I forgot to put at least a link:
http://www.freepascal.org/docs-html/ref/refse38.html
Jesus Reyes A.
____________________________________________________________________________________ ¡Sé un mejor besador!
Comparte todo lo que sabes sobre besos.
http://mx.yahoo.com/promos/mejorbesador.html
Images are so big that is difficult to follow the diagrams.. Jesus Reyes A.…
Please use the PDF version, not the HTML version. The HTML is generated from the LaTeX, but the quality is in general rather poor.
Michael.
sorry I forgot to put at least a link: http://www.freepascal.org/docs-html/ref/refse38.htm…
Thanks.
Maybe the wiki page should be marked as obsolete and a link to the reference should be added?
Why is the local variable block needed?
Mattias
Maybe, yes.
Why is the local variable block needed?
It is not. I asked the same question. It was added for symmetry reasons: if a local type block is allowed, then a var block should also be allowed.
But they are not different from local fields.
Michael.
Strange. ok.
What local types are/will be allowed?
For example, this is currently not allowed:
generic TTree<T> = class(TObject)
type public
TTreeNode = specialize TNode<T>;
end;And this neither:
generic TTree<T> = class(TObject)
type public
TTreeNode = class
Data: T;
end;
end;OTOH records and pointers are allowed.
Will this stay, or is this just not yet implemented?
Mattias
Is there a need to support this?
Well, it seems rather strange that the type block would not allow all possible types.
Michael.
Only a few types can be generic as well. Nested classes cause a lot of hidden pitfalls, that's why they aren't allowed.
OK, probably I should add this to the docs. I assume all types can be defined except classes and generics ?
Michael.
I don't need them.
I'm just asking for the codetools.
So I guess the answer is: Will stay. (read: there are no further plans).
.. and objects and interfaces.
It seems generic objects and interfaces are allowed, but this is not yet documented.
What about generic records? Will they be implemented?
Mattias
On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) Strange. ok. What local types are/will be…
Shouldn't this be allowed?
Perhaps it can only work with a complete TTreeNode description, probably the TNode is specific for use by TTree anyway. But that would limit it to being a record.
Micha
Is there a need to support this?
Imho the example given by Mattias demonstrates that a similar construct would be desirable; or is there another way to accommodate for the aggregation of generic classes?
I think TTree/TNode is a typical example where you'd like to use the generic type used for TTree to create the corresponding TNode.
type
generic TNode<T> = class
type TChildList = TList<TNode>; // and how about this?
Data:T;
Children:TChildList;
end;
generic TTree<T> = class
type TTreeNode = specialize TNode<T>;
Root:TTreeNode;
GetNode(Index:integer):TTreeNode;
GetNodeData(Index:integer):T;
end;...
function TTree.GetNodeData(Index:integer):T;
begin
Result:=GetNode(Index).Data;
end;Regards,
Bram