Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2007-08

Generics

15 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 7 lines
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.

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.

Reply by email

Jesus Reyes
to Michael Van Canneyt
--- Michael Van Canneyt wrote 18 lines
On Thu, 16 Aug 2007, Mattias Gaertner wrote: > > 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. 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

Reply by email

Jesus Reyes
to Jesus Reyes
--- Jesus Reyes wrote 23 lines
--- Michael Van Canneyt escribió: > > > On Thu, 16 Aug 2007, Mattias Gaertner wrote: > > > > > 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. > > 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..

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

Reply by email

Michael Van Canneyt
to Jesus Reyes: Images are so big that is difficult to follow the diagrams.. Jesus Reyes A.…
Jesus Reyes wrote 23 lines
--- Michael Van Canneyt escribió: > > > On Thu, 16 Aug 2007, Mattias Gaertner wrote: > > > > > 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. > > 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..

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.

Reply by email

Mattias Gaertner
to Jesus Reyes: sorry I forgot to put at least a link: http://www.freepascal.org/docs-html/ref/refse38.htm…
Show quoted text 30 lines
--- Jesus Reyes escribió: > > --- Michael Van Canneyt escribió: > > > > > > > On Thu, 16 Aug 2007, Mattias Gaertner wrote: > > > > > > > > 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. > > > > 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.. sorry I forgot to put at least a link: http://www.freepascal.org/docs-html/ref/refse38.html

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

Reply by email

Michael Van Canneyt
to Mattias Gaertner
Mattias Gaertner wrote 38 lines
On Thu, 16 Aug 2007 14:59:47 -0500 (CDT) Jesus Reyes wrote: > > --- Jesus Reyes escribió: > > > > > --- Michael Van Canneyt escribió: > > > > > > > > > > > On Thu, 16 Aug 2007, Mattias Gaertner wrote: > > > > > > > > > > > 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. > > > > > > 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.. > > sorry I forgot to put at least a link: > > http://www.freepascal.org/docs-html/ref/refse38.html Thanks. Maybe the wiki page should be marked as obsolete and a link to the reference should be added?

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.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 8 lines
[...] > 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.

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

Reply by email

Florian Klaempfl
to Mattias Gaertner
Show quoted text 34 lines
On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) Michael Van Canneyt wrote: > [...] >> 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. 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?

Is there a need to support this?

Reply by email

Michael Van Canneyt
to Florian Klaempfl
Florian Klaempfl wrote 36 lines
Mattias Gaertner schrieb: > On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) > Michael Van Canneyt wrote: > > > [...] > > > 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. > > 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? Is there a need to support this?

Well, it seems rather strange that the type block would not allow all possible types.

Michael.

Reply by email

Florian Klaempfl
to Michael Van Canneyt
Show quoted text 40 lines
On Fri, 17 Aug 2007, Florian Klaempfl wrote: > Mattias Gaertner schrieb: >> On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) >> Michael Van Canneyt wrote: >> >>> [...] >>>> 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. >> 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? > Is there a need to support this? Well, it seems rather strange that the type block would not allow all possible types.

Only a few types can be generic as well. Nested classes cause a lot of hidden pitfalls, that's why they aren't allowed.

Reply by email

Michael Van Canneyt
to Florian Klaempfl
Florian Klaempfl wrote 44 lines
Michael Van Canneyt schrieb: > > On Fri, 17 Aug 2007, Florian Klaempfl wrote: > > > Mattias Gaertner schrieb: > > > On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) > > > Michael Van Canneyt wrote: > > > > > > > [...] > > > > > 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. > > > 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? > > Is there a need to support this? > > Well, it seems rather strange that the type block would not allow all > possible types. 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.

Reply by email

Mattias Gaertner
to Michael Van Canneyt
Show quoted text 22 lines
[...] > > > > 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? > > > Is there a need to support this?

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).

Show quoted text 8 lines
> > Well, it seems rather strange that the type block would not allow > > all possible types. > > 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 ?

.. 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

Reply by email

Micha Nelissen
to Mattias Gaertner: On Thu, 16 Aug 2007 23:31:25 +0200 (CEST) Strange. ok. What local types are/will be…
Mattias Gaertner wrote 6 lines
For example, this is currently not allowed: generic TTree<T> = class(TObject) type public TTreeNode = specialize TNode<T>; end;

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

Reply by email

Bram Kuijvenhoven
to Florian Klaempfl: Is there a need to support this?
Florian Klaempfl wrote 21 lines
Mattias Gaertner schrieb: > 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? 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

Reply by email