[fpc-devel] Language extension: absolute for classes

2006-09-30 Thread Micha Nelissen
Hi,

I want to bring up the following scenario: (need fixed font)

   B  --  G
   |   |
   A  --  F

All are classes, and usually A 'owns' F. So A has a field 'Field' of
type F. Now, whenever A creates F, B overrides this (in virtual method
or class type) to create a G.

The problem now is that every time B wants to access G, it has to
typecast Field to G.

I want to propose something like:

type
  B = class(A)
  protected
Field: G absolute Field;
...
  end;

Whenever the implementation of methods of B (or descendants of B)
accesses Field, the compiler will use type G automatically, so that no
typecast is necessary.

The compiler option -Criot might be used to check whether the type is
actually the suggested type, in extension to the current behaviour where
class typecasts are converted to 'as' under usage of this switch.

I realize that this is only a 'saving-typing' language extension, but it
does save significant amounts of typing and would make the code more
readable (IMHO).

It would be useful in the LCL: TLCLComponent.FWidgetSetClass which is a
metaclasstype, and TWinControl (see wincontrol.inc:2053 for current
typecast example), TEdit etc. want to use a descendant metaclasstype.
It would also be useful in lNet: TLConnection has a FIterator which is a
TLSocket, but descendants can choose to create descendants of TLSocket
instead.

Opinions ?

Micha
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Shootout

2006-09-30 Thread Daniël Mantione


Op Sat, 30 Sep 2006, schreef Marc Weustink:

 Daniël Mantione wrote:
  Hi,
  
  Encouraged by Vincent I made an attempt to implement the Chameneos 
  benchmark of the Shootout. 
 
 ??? Last week I submitted chamenos to shootout and it got accepted.

Argh, then we have been double work :)

 It's only the work of one night, so it might need some improvement (it'
 isn't faster that the C implementation for instance)

Mine neither :/

Daniël___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Language extension: absolute for classes

2006-09-30 Thread Christian Iversen
On Saturday 30 September 2006 12:23, Marco van de Voort wrote:
  I realize that this is only a 'saving-typing' language extension, but it
  does save significant amounts of typing and would make the code more
  readable (IMHO).

 You can achieve the same with generics ?  Specialize a class with T=G ?

Something similar can also be done with interfaces (but in this case, generics 
is probably a cleaner way to do it)

-- 
Regards,
Christian Iversen
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel