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

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

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

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


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

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

Sven Barth-2

Am 10.12.2013 11:53 schrieb "Dennis Poon" <[hidden email]>:
>
> 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.

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


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

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

Anthony Walter-3
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.

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

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

Jonas Maebe-2

On 10 Dec 2013, at 15:58, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Anthony Walter-3
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;


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

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

Jonas Maebe-2

On 10 Dec 2013, at 18:10, 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Marco van de Voort
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)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

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

Jonas Maebe-2

On 10 Dec 2013, at 18:16, Marco van de Voort wrote:

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

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

Anthony Walter-3
In reply to this post by Marco van de Voort
Marco:

I agree with you, and that was also my advice I said in my first post (the third message in this thread).

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal