Recent

Author Topic: Proposing 4 New Ideas - #4 Standard Compiler Methods  (Read 1469 times)

IndigoBoy83

  • New member
  • *
  • Posts: 9
Proposing 4 New Ideas - #4 Standard Compiler Methods
« on: March 22, 2019, 01:38:59 pm »
PAGE #4 - Introducing Standard Compiler Methods

We now demonstrate the ease of using, what I call, "standard compiler methods".

I suggest that every standard compiler method starts with the numeral sign: "#".

For example, I suggest that every object/class should come endowed with two standard write methods, one for Write(*) and the other for Writeln(*).

When one writes an object/class this standard write method is invoked. 

It should be made virtual so that the programmer can override it as he wishes.

Consider the following code as example of the use of a standard write method.

Code: Pascal  [Select][+][-]
  1. Program Example_Of_Standard_Write_Method;
  2.  
  3. interface
  4.  
  5. uses
  6.   Classes;
  7.  
  8. type
  9.     some_object_type = object
  10.       Procedure #Write; virtual;
  11.       Procedure #Writeln; virtual;
  12.     end;
  13.  
  14. implementation
  15.  
  16. Procedure some_object_type.#Write;
  17. begin
  18.   write( 'Now you can write an object!' );
  19. end;
  20.  
  21. Procedure some_object_type.#Writeln;
  22. begin
  23.   #Write;
  24.   writeln;
  25. end;
  26.  
  27. var
  28.    some_object : some_object_type;
  29.  
  30. begin
  31.   New( some_object );
  32.  
  33.   some_object.#Writeln;  // Outputs: "Now you can write an object!"
  34.   writeln( 'My object writes: "', some_object, '" !' );  // Outputs: "My object writes: "Now you can write an object!" !"
  35.  
  36.   Dispose( some_object );
  37. end;

Output for previous code:

Now you can write an object!
My object writes: "Now you can write an object!" !


Observe that in the line
Code: Pascal  [Select][+][-]
  1. writeln( 'My object write: "', some_object, '" !' );
the writeln function accesses some_object.#Write; if this standard compiler method is not implemented within the object/class, then we should always have some default method to be used.

So now we can send any general class/object to the write or writeln functions.  Other standard compiler methods should be made as needed (perhaps #read, #readln, ..).
« Last Edit: March 22, 2019, 01:47:28 pm by IndigoBoy83 »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Proposing 4 New Ideas - #4 Standard Compiler Methods
« Reply #1 on: March 22, 2019, 02:01:53 pm »
Well, there is tobject.tostring virtual method already !??!?

 

TinyPortal © 2005-2018