вторник, 11 августа 2015 г.

Briefly. I finished words redefining

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

Follow-up to Briefly. Wonder of words redefining

Now this code:

USES
 axiom:ComboBox
 axiom:ComboTree
;
 
REDEFINITION
 : pop:ComboBox:DropDown
  OBJECT IN aCombo
  if ( aCombo Is class::TvtComboTree ) then
   ( aCombo pop:ComboTree:DropDown )
  else
   ( aCombo inherited )
 ; // pop:ComboBox:DropDown


can be rewritten in this way:

USES
 axiom:ComboBox
 axiom:ComboTree
 axiom:ComboTreeEx
;
 
REDEFINITION
 : pop:ComboBox:DropDown
  OBJECT IN aCombo
  callIfAccepted aCombo [ 
   [ @ class::ComboTreeEx @ pop:ComboTreeEx:DropDown ]
    // pop:ComboTreeEx:DropDown can be called if aCombo is compliable with ComboTreeEx
   [ @ class::ComboTree @ pop:ComboTree:DropDown ]
    // pop:ComboTree:DropDown can be called if aCombo is compliable with ComboTree
   [ nil @ inherited ]
    // can be called if all other branches do not pass 
  ] // callIfAccepted aCombo
 ; // pop:ComboBox:DropDown

It seems so simple “under hood”.

I will write later. We can even write in this way:

USES
 axiom:ComboBox
 axiom:ComboTree
 axiom:ComboTreeEx
;
 
REDEFINITION
 : pop:ComboBox:SetValue
  ANY IN aValue
  OBJECT IN aCombo
  callIfAccepted [ aValue aCombo ] [ 
   [ @ INTEGER @ class::ComboTreeEx @ pop:ComboTreeEx:SetValue ]
    // pop:ComboTreeEx:DropDown can be called if aCombo is compatible with ComboTreeEx,
    // and aValue is compatible with INTEGER
   [ @ STRING @ class::ComboTree @ pop:ComboTree:SetValue ]
    // pop:ComboTree:DropDown can be called if aCombo is compatible with ComboTree,
    // and aValue is compatible with STRING
   [ @ ANY nil @ inherited ]
    // can be called if all other branches do not pass
  ] // callIfAccepted aCombo
 ; // pop:ComboBox:DropDown

We can make it more simple aiming to minimize using of @.

We can do in this way:

USES
 axiom:ComboBox
 axiom:ComboTree
 axiom:ComboTreeEx
;
 
REDEFINITION
 : pop:ComboBox:SetValue
  ANY IN aValue
  OBJECT IN aCombo
  callIfAccepted [ aValue aCombo ] [ 
   [ @ INTEGER @ class::ComboTreeEx @ pop:ComboTreeEx:SetValue ]
    // pop:ComboTreeEx:DropDown can be called if aCombo is compatible with ComboTreeEx,
    // and aValue is compatible with INTEGER
   [ @ STRING @ class::ComboTree @ pop:ComboTree:SetValue ]
    // pop:ComboTree:DropDown can be called if aCombo is compatible with ComboTree,
    // and aValue is compatible with STRING
   [ @ STRING @ class::ComboBox @ inherited ]
    // inherited can be called if aCombo is compatible with ComboBox,
    // and aValue is compatible with STRING
   [ @ ANY @ ANY @ NotImplemented ]
    // can be called if all other branches do not pass
    // and causes error NotImplemented
  ] // callIfAccepted aCombo
 ; // pop:ComboBox:DropDown

Or in this way:

USES
 axiom:ComboBox
 axiom:ComboTree
 axiom:ComboTreeEx
;
 
REDEFINITION
 : pop:ComboBox:SetValue
  ANY IN aValue
  OBJECT IN aCombo
  callIfAccepted [ aValue aCombo ] [ 
   @[ INTEGER class::ComboTreeEx pop:ComboTreeEx:SetValue ]
    // pop:ComboTreeEx:DropDown can be called if aCombo is compatible with ComboTreeEx,
    // and aValue is compatible with INTEGER
   @[ STRING class::ComboTree pop:ComboTree:SetValue ]
    // pop:ComboTree:DropDown can be called if aCombo is compatible with ComboTree,
    // and aValue is compatible with STRING
   @[ STRING class::ComboBox inherited ]
    // inherited can be called if aCombo is compatible with ComboBox,
    // and aValue is compatible with STRING
   @[ ANY ANY NotImplemented ]
    // can be called if all other branches do not pass
    // and causes error NotImplemented
  ] // callIfAccepted aCombo
 ; // pop:ComboBox:DropDown

It minimizes using of @.

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

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