Начинаю проникаться функциональным подходом.
При написании своих шаблонов кодогенерации.
Или скорее - "моей интерпретацией (интертрепацией) функционального подхода".
Всякие там map/reduce и иже с ними.
А также ленивые вычисления и кеширование ранее вычисленного результата.
Без всяких правда "закорючек" и "монад".
Ну и "сам подход": Вход -> Преобразование -> Выход.
Ну и типа работа с коллекциями (filter/map):
При написании своих шаблонов кодогенерации.
Или скорее - "моей интерпретацией (интертрепацией) функционального подхода".
Всякие там map/reduce и иже с ними.
А также ленивые вычисления и кеширование ранее вычисленного результата.
Без всяких правда "закорючек" и "монад".
Ну и "сам подход": Вход -> Преобразование -> Выход.
Ну и типа работа с коллекциями (filter/map):
ARRAY FUNCTION .OperationsNeededElements ARRAY IN anArray anArray .mapToTargetAndValueType> .join> ( anArray .filter> .IsMessage .filter> ( .GetUP "Message ID" 'CM_' SWAP StartsStr ) .map> ( DROP GarantModel::Controls ) ) // .join> .joinWithLambded> anArray ( .Parameters .mapToTargetAndValueType> ) .joinWithLambded> anArray ( .AttributesAndOperations call.me ) .joinWithLambded> anArray .CanRaise .joinWithLambded> anArray .CanRaiseInSet >>> Result ; // .OperationsNeededElements
ARRAY FUNCTION .CommaListWith()
ARRAY IN aList
[
VAR l_WasComma
false >>> l_WasComma
aList .for> (
.WithComma: l_WasComma .KeepInStack
)
] .With() >>> Result
; // .CommaListWith()
ARRAY elem_func ParametersList
Cached:
(
Self .MethodParameters .map> .Name .CommaListWith()
)
>>> Result
; // ParametersList
...
elem_proc OutUses:
STRING IN aUCPrefix
^ IN aUsed
^ IN aLambda
ARRAY VAR l_Used
aUsed DO >>> l_Used
ARRAY FUNCTION .filterUsed>
ARRAY IN anArray
anArray
.filter> (
IN anItem
anItem .UnitName >>> anItem
if ( anItem l_Used array:Has ! ) then
begin
anItem array:AddTo l_Used
true
end
else
begin
false
end
) >>> Result
; // .filterUsed>
'uses' .Out
VAR l_NeedComma
false >>> l_NeedComma
Indented: (
aLambda DO
.map> .UnitProducer
.filterNil>
.filterMixIns>
.filter> ( Self ?!= )
.filter> ( .UnitName Self .UnitName ?!= )
.filter> ( .UnitName 'System' ?!= )
//.map> .UnitName
.filterUsed>
.for> (
IN anItem
anItem .IfDef: ( anItem .UnitName .WithComma: l_NeedComma .Out )
) // .for>
if ( Self .IsElementProxy ) then
begin
Self .UserCode: aUCPrefix ()
end // ( Self .IsElementProxy )
) // Indented:
';' .Out
OutLn
; // OutUses:
...
BOOLEAN elem_func HasFactory
Cached:
(
Self .Operations .filter> .IsFactory .CountIt > 0
)
>>> Result
; // HasFactory
...
BOOLEAN elem_func NeedFinalize
Cached:
(
RULES
( Self IsNil )
false
DEFAULT
(
Self .Attributes
.filter> ( .Target .IsManaged )
.CountIt > 0
OR ( Self .MainAncestor call.me )
)
; // RULES
)
>>> Result
; // NeedFinalize
...
BOOLEAN elem_func InheritsFrom
STRING IN anAncestor
anAncestor :Cached:
(
RULES
( Self .TypeName anAncestor == )
true
DEFAULT
(
Self .Inherits
.filter> ( anAncestor call.me )
.CountIt > 0
)
; // RULES
)
>>> Result
; // InheritsFrom
...
BOOLEAN elem_func IsConstructorsHolder
( Self .MainAncestor IsNil ! )
AND ( Self .Attributes .CountIt <= 0 )
AND ( Self .Operations .filter> ( .IsConstructor ! ) .CountIt <= 0 )
>>> Result
; // IsConstructorsHolder
...
BOOLEAN elem_func InheritsOrImplementsAcceptableForScripts
Cached:
(
RULES
( Self .Inherits .filter> .IsAcceptableForScripts .CountIt > 0 )
true
( Self .Implements .filter> .IsAcceptableForScripts .CountIt > 0 )
true
DEFAULT
false
; // RULES
)
>>> Result
; // InheritsOrImplementsAcceptableForScripts
...
BOOLEAN elem_func SomeAncestorImplements
ModelElement IN anIntf
BOOLEAN elem_func ImplementsLoc
Self .Implements .filter> ( anIntf ?== ) .CountIt > 0 >>> Result
; // ImplementsLoc
anIntf :Cached:
(
RULES
( Self .IsTypedef )
RULES
( Self .IsPointer )
false
DEFAULT
( Self .MainAncestorPrim anIntf call.me )
; // RULES
( Self .Inherits .filter> .ImplementsLoc .CountIt > 0 )
true
( Self .Inherits .filter> ( anIntf call.me ) .CountIt > 0 )
true
( Self .Implements .filter> .IsMixIn .filter> .ImplementsLoc .CountIt > 0 )
true
( Self .Implements .filter> .IsMixIn .filter> ( anIntf call.me ) .CountIt > 0 )
true
DEFAULT
false
; // RULES
)
>>> Result
; // SomeAncestorImplements
...
BOOLEAN elem_func InheritsOrImplementsMixIn
Cached:
(
RULES
( Self .Inherits .filter> .IsMixIn .CountIt > 0 )
true
( Self .Implements .filter> .IsMixIn .CountIt > 0 )
true
DEFAULT
false
; // RULES
)
>>> Result
; // InheritsOrImplementsMixIn
...
BOOLEAN elem_func ImplementsMixIn
Cached:
(
RULES
//( Self .Inherits .filter> .IsMixIn .CountIt > 0 )
// true
( Self .Implements .filter> .IsMixIn .CountIt > 0 )
true
DEFAULT
false
; // RULES
)
>>> Result
; // ImplementsMixIn
...
elem_iterator OtherMixinValuesUses
[empty]
.joinWithLambded> ( Self .Inherits ) ( .MixInValues .mapToTarget> )
.joinWithLambded> ( Self .Inherits ) call.me
>>> Result
; // OtherMixinValuesUses
...
BOOLEAN elem_func NeedsFakeMethod
Cached:
(
RULES
( Self .IsAutoHelper )
true
( Self .Properties .filter> ( .ReadsField ! ) .CountIt > 0 )
true
DEFAULT
false
; // RULES
)
>>> Result
; // NeedsFakeMethod
...
BOOLEAN elem_func IsSimpleClass
Cached:
(
RULES
( Self .IsStereotype st_UseCaseControllerImp )
( Self .Abstraction at_abstract != )
( Self .IsStereotype st_ViewAreaControllerImp )
( Self .Abstraction at_abstract != )
( Self .IsStereotype st_SimpleClass )
true
( Self .IsStereotype st_ObjStub )
true
( Self .IsService )
true
( Self .IsServiceImplementation )
true
( Self .IsScriptKeyword )
true
( Self .IsTestCase )
true
( Self .IsStereotype st_GuiControl )
true
( Self .IsVCMForm )
true
( Self .IsStereotype st_VCMFinalForm )
true
( Self .IsStereotype st_VCMContainer )
true
( Self .IsStereotype st_VCMFinalContainer )
true
DEFAULT
false
; // RULES
)
>>> Result
; // IsSimpleClass
BOOLEAN elem_func IsScriptKeywordsPack
Self .IsStereotype st_ScriptKeywordsPack >>> Result
; // IsScriptKeywordsPack
BOOLEAN elem_func IsUtilityPack
Cached:
(
RULES
( Self .IsStereotype st_UtilityPack )
true
( Self .IsScriptKeywordsPack )
true
DEFAULT
false
; // RULES
)
>>> Result
; // IsUtilityPack
BOOLEAN elem_func IsInterfaces
Cached:
(
RULES
( Self .IsStereotype st_Interfaces )
true
( Self .IsStereotype st_InternalInterfaces )
true
DEFAULT
false
; // RULES
)
>>> Result
; // IsInterfaces
: .FirstElement
ARRAY IN anArray
ModelElement VAR l_Found
nil >>> l_Found
anArray .trunc> ( DROP l_Found IsNil ) .for> ( >>> l_Found )
l_Found
; // .FirstElement
: .SecondElement
ARRAY IN anArray
ModelElement VAR l_Found
nil >>> l_Found
INTEGER VAR l_Index
0 >>> l_Index
anArray .trunc> ( DROP l_Index < 2 ) .for> (
IN anItem
( l_Index 1 == ) ?
( anItem >>> l_Found )
INC l_Index
) // anArray .trunc> ( DROP l_Index < 2 ) .for>
l_Found
; // .SecondElement
Комментариев нет:
Отправить комментарий