Sign in Join

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

Mailing lists / fpc-pascal / 2013-12

how to define a generic subclass inheriting from another generic class?

9 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

Dennis Poon

What is the syntax. I could not find it in google.

e.g. in unit fgl,

generic TFPGMap<TKey, TData>=class(TFPSMap)
....
end;

How do I define a subclass TMyMap inheriting from TFPGMap without first specializing it?

I assumed

generic TMyMap <TKey, TData> = class(generic TFPGMap<TKey, TData>) ...
end

but fpc 2.6.2 did not accept this.

Please help.

Dennis

Sven Barth
to Dennis Poon
"Dennis Poon" wrote 12 lines
What is the syntax. I could not find it in google. e.g. in unit fgl, generic TFPGMap<TKey, TData>=class(TFPSMap) .... end; How do I define a subclass TMyMap inheriting from TFPGMap without first

specializing it?

Show quoted text 10 lines
I assumed generic TMyMap <TKey, TData> = class(generic TFPGMap<TKey, TData>) ... end but fpc 2.6.2 did not accept this. Please help.

The pre-2.7.1 compilers don't support this. In 2.7.1 the syntax is:

generic TMyMap <TKey, TData> = class(specialize TFPGMap<TKey, TData>)
   //...
end;

(and yes, it's "specialize", not "generic" and it's working as intended)

Regards,
Sven

Anthony Walter
to Sven Barth

Or more simply in the latest Delphi mode:

  TMyMap<TKey, TData> = class(TFPGMap<TKey, TData>)
    // ...
  end;

Which is how the FPC mode syntax should have been to begin with IMO.

Jonas Maebe
to Anthony Walter
Anthony Walter wrote
Which is how the FPC mode syntax should have been to begin with IMO.

Can we please not restart that discussion? As has been mentioned several times before,
a) the FPC and Delphi syntaxes were developed in parallel, so neither could take the other as an example (well, theoretically Delphi could have taken FPC's approach, since theirs was developed behind closed doors while ours was in the open)
b) the FPC syntax favours being explicit/verbose and making things easy for the parser (no ambiguities about the meaning of "<" or ">" anywhere), while Delphi's syntax favours conciseness and similarity to C++

Neither approach is "how it should have been", except for in the eye of the beholder, and arguing either case again is not going to change anything either.

Jonas

Anthony Walter
to Jonas Maebe

The way FPC handles generics went against all other previous Pascal conventions. You always had

A) type block

which then is always followed by

B) an identifier

and then a

C) type definition terminated with a semi colon

B and C can then be repeated in pairs until a different block is declared (const, var, threadvar, resourcestring, function, procedure, begin or end)

So what you always had with regards to a type block is:

A
  B C;
  B C;
  B C;

Where A is he keyword 'type', B is and identifier, and C is the type definition.

Then someone went and decided that rather than scan ahead for a < after the identifier, they wanted another keyword in front of B, which breaks the whole pattern.

A
  B C;
  generic B C;
  B C;
Jonas Maebe
to Anthony Walter
Anthony Walter wrote
The way FPC handles generics went against all other previous Pascal conventions. You always had

If you really want to restart the discussion, please move it to fpc-other.

Thanks,

Jonas
FPC mailing lists admin

Marco van de Voort
to Jonas Maebe

In our previous episode, Jonas Maebe said:

> The way FPC handles generics went against all other previous Pascal > conventions. You always had If you really want to restart the discussion, please move it to fpc-other.

(or, if 2.7.1, use $mode delphi and the Delphi syntax)

Jonas Maebe
to Marco van de Voort
Marco van de Voort wrote 7 lines
In our previous episode, Jonas Maebe said: >> The way FPC handles generics went against all other previous Pascal >> conventions. You always had > > If you really want to restart the discussion, please move it to fpc-other. (or, if 2.7.1, use $mode delphi and the Delphi syntax)

He already mentioned in his first message that this is an alternative, which is fine. It's only the discussion about which syntax is best/most logical/most Pascalish/... that has no place anymore on this list.

Jonas