L
Lieven De Foor
Guest
In functional programming languages, functions are first-class citizens. This means you can assign a function to a variable and pass it as parameter to another function or return it from other functions. In ABL there is one construct in which you can specify a method as a parameter, and that is when attaching an event handler to an event: myButton:Click:Subscribe(myButton_Click). We can (ab)use this to have some functional programming capabilities: CLASS FunctionalProgramming.Calculator: DEFINE PRIVATE EVENT Calculator VOID (a AS INTEGER, b AS INTEGER, OUTPUT Result_ AS DECIMAL). METHOD PRIVATE VOID Sum(a AS INTEGER, b AS INTEGER, OUTPUT Result_ AS DECIMAL): Result_ = a + b. END METHOD. METHOD PRIVATE VOID Multiply(a AS INTEGER, b AS INTEGER, OUTPUT Result_ AS DECIMAL): Result_ = a * b. END METHOD. CONSTRUCTOR Calculator(): DEFINE VARIABLE Result_ AS DECIMAL NO-UNDO. Calculator:Subscribe(Sum). Calculator
ublish(3, 4, OUTPUT Result_). Calculator:Unsubscribe(Sum). MESSAGE Result_ VIEW-AS ALERT-BOX. Calculator:Subscribe(Multiply). Calculator
ublish(3, 4, OUTPUT Result_). Calculator:Unsubscribe(Multiply). MESSAGE Result_ VIEW-AS ALERT-BOX. END CONSTRUCTOR. END CLASS. The boilerplate code (Subscribe/Publish/Unsubscribe) might be able to get isolated in an include file. If anyone has any other creative ideas on how this pattern could be used, please share them here...
Continue reading...


Continue reading...