//Logging the number of calls to an Int->Int->Int function by embedding it in a closure
//Wrapping the whole inside a main function to test closure cleanup

function int main1() {
    function int add(int a, int b) a+b;

    var (int)->int add5;
    
    var ()->int getCalls;

    function (int,int)->int logCalls((int,int)->int f) {
        var int calls;
        calls := 0;
        function int getCalls2() calls;
        getCalls := getCalls2;
        function int return(int first, int second) {
            calls := calls + 1;
            f(first,second)
        };
        return
    };

    var add add_;
    add_ := logCalls(add);

    print(add_(1,6), add_(10,5));
    print(getCalls());
};

main1();
