понедельник, 12 октября 2015 г.

#821. Briefly. Words redefining

Original in Russian: http://programmingmindstream.blogspot.ru/2015/08/blog-post_6.html

Follow-up to - Briefly. Wonder of words redefining http://programmingmindstream.blogspot.com/2015/07/briefly-wonder-of-words-redefining.html

I wrote this:

REDEFINITION
 STRING FUNCTION ToPrintable
   IN aValue
  if ( aValue IsArray ) then
   ( [ '[ ' for aValue ( @SELF DO ) ' ]' ] ' ' strings:CatSep >>> Result )
  else
   ( aValue inherited >>> Result )
 ; // ToPrintable

The arrays were not printable before, and now they are.

We can also do in this way:

REDEFINITION
 STRING FUNCTION ToPrintable
   IN aValue
  if ( aValue IsObject ) then
   (
    if ( aValue IS class:TComponent ) then
     (
       [ aValue pop:Component:Name ':' aValue pop:object:ClassName ]
        strings:Cat >>> Result
     )
    else
     ( aValue pop:object:ClassName >>> Result )
   )
  else
   ( aValue inherited >>> Result )
 ; // ToPrintable

The items are printable too.

Virtuality or no virtuality. REDEFINITIONs “thread” as “interrupt handlers” or “cookies”.

One REDEFINITION decodes the other.

Actually, there are some “subtleties” in the call-out procedure. FIRST we make REDEFINITION for IsObject, ONLY AFTER – for IsArray.

In this case recursion works properly.

If we need “real virtuality”, we can add virtuality.

Later I will write how.

To cut it short, here you are:

REDEFINITION
 STRING FUNCTION ToPrintable
   IN aValue
   PUBLIC STATIC VAR g_ToPrintable = inherited
   // - memorizes the reference to inherited
  aValue g_ToPrintable DO >>> Result
  // - executes the reference
  //   It is clear, this reference can be “later” redefined
  // In this way:
 
  // ... in some OTHER part of the code ...
  // We write the following:
 
  STRING FUNCTION ClassToPrintable
   IN aValue
 
   VOID IMMEDIATE OPERATOR CompileCallToPrintable
    ToPrintable :: g_ToPrintable CompileValue @ DO CompileValue
    // - compiles call-by reference of g_ToPrintable
   ; // CompileCallToPrintable
 
   if ( aValue IsObject ) then
    (
     if ( aValue IS class:TComponent ) then
      (
        [ aValue pop:Component:Name ':' aValue pop:object:ClassName ]
         strings:Cat >>> Result
      )
     else
      ( aValue pop:object:ClassName >>> Result )
    )
   else
    ( aValue CompileCallToPrintable >>> Result )
  ; // ClassToPrintable
  
  ToPrintable :: g_ToPrintable := ClassToPrintable 
  // - redefines the reference
  // Next, the recursion following the chain
  // In this way:
 
  STRING FUNCTION ArrayToPrintable
    IN aValue
   if ( aValue IsArray ) then
    ( [ '[ ' for aValue ( @SELF DO ) ' ]' ] ' ' strings:CatSep >>> Result )
   else
    ( aValue CompileCallToPrintable >>> Result )
  ; // ArrayToPrintable
 
  ToPrintable :: g_ToPrintable := ArrayToPrintable 
  // - redefines the reference
 
 ; // ToPrintable

Why do we need it all?

We need to extend the definition of grammar and transform the domain area if we can not make changes to “design classes”.

For example, testers can use it.

Later I will write how to change design classes (see Agent-oriented programming and Aspect-oriented programming).

Actually, these REDEFINITIONs are used to EXTEND the DEFINITION of “aspects” that do not MATCH the “cross-cutting hierarchy” of design classes.

They are ASIDE from inheritance hierarchy.

Of course, this is not for the end user but for those who want and CAN extend the definition of grammar.

A note:

 strings:Cat - concatenates strings in array
 strings:CatSep - concatenates strings in array via separator
 @SELF DO – calls itself recursively
 CompileValue – compiles reference to the word

What I described above is a paradigm of “check points” (in Russian).

(+) About tests and specially fitted “check points”
(+) Briefly. Shooting the breeze. Dependancy inversion
(+) Briefly. Again about dependency inversion
(+) Briefly. Blog, style of articles writing and polemic (in Russian)
(+) Depression, or Falsity of hResult and other ErrorCode’s

Комментариев нет:

Отправить комментарий