<commit_before>local sentinel = {}

local function exit (...) print('result', ...) print('exit') end

local function operator_prototype (operators, execute)
    local hungry = true
    local operands = {}
    local rest = {}
    return function (...)
        print('operands', unpack (operands))
        if hungry then
            for i, v in ipairs({...}) do
                if v == sentinel then
                    hungry = false
                else
                    if hungry then table.insert (operands, v) else table.insert (rest, v) end
                end
            end
            -- debug
            -- for i, v in ipairs (operands) do print(i, v) end
            -- debug
            if not hungry then
                table.remove (operators)
                local output = {execute (operands)}
                for i, v in ipairs (rest) do table.insert (output, v) end
                operators[#operators] (unpack (output))
            end
        end
    end
end

local function combinator_prototype (op, result)
    return function (operands)
        for i, v in ipairs(operands) do result = op(result, v) end
        return result
    end
end

local add = combinator_prototype (function (x, y) return x + y end, 0)
local sub = combinator_prototype (function (x, y) return x - y end, 0)

local operators = {exit}
table.insert (operators, operator_prototype (operators, add))
operators[#operators] (1, 2)
operators[#operators] (3, 4)
operators[#operators] (5, 6)
table.insert (operators, operator_prototype (operators, sub))
operators[#operators] (2, 3, sentinel)
operators[#operators] (sentinel, 7, 8)<commit_msg>Clean-up.<commit_after>local sentinel = {}

local function exit (...) print('result', ...) print('exit') end

local function operator_prototype (operators, execute)
    local hungry = true
    local operands = {}
    local rest = {}
    return function (...)
        print('operands', unpack (operands))  -- debug
        if hungry then
            for i, v in ipairs({...}) do
                if v == sentinel then
                    hungry = false
                else
                    if hungry then table.insert (operands, v) else table.insert (rest, v) end
                end
            end
            if not hungry then
                table.remove (operators)
                local output = {execute (operands)}
                for i, v in ipairs (rest) do table.insert (output, v) end
                operators[#operators] (unpack (output))
            end
        end
    end
end

local function combinator_prototype (op, result)
    return function (operands)
        for i, v in ipairs(operands) do result = op(result, v) end
        return result
    end
end

local add = combinator_prototype (function (x, y) return x + y end, 0)
local sub = combinator_prototype (function (x, y) return x - y end, 0)

local operators = {exit}
table.insert (operators, operator_prototype (operators, add))
operators[#operators] (1, 2)
operators[#operators] (3, 4)
operators[#operators] (5, 6)
table.insert (operators, operator_prototype (operators, sub))
operators[#operators] (2, 3, sentinel)
operators[#operators] (sentinel, 7, 8)
{'fraction_non_alphanumeric': 0.10788643533123028, 'fraction_numerical': 0.007570977917981073, 'mean_word_length': 2.180541624874624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1951542', 'n_tokens_mistral': 942, 'n_tokens_neox': 892, 'n_words': 324}