<commit_before>"use strict";

// 4 == 3 + 1 // lam
//   == 0 + 1 + 3 == 1 + 1 + 2 == 2 + 1 + 1 == 3 + 1 + 0
function gen(vars, level) {
    var exps = [];
    exps[0] = vars.map(v => ["var", v]);
    
    for (var n = 1; n <= level; n++) {
        var lvN = [];
        for (let e of exps[n - 1]) {
            for (let v of vars) {
                lvN.push(["lam", v, e]);    
            }
        }
        for (let i = 0; i <= n - 1; i++) {
            let j = (n - 1) - i;
            for (let e1 of exps[i]) {
                for (let e2 of exps[j]) {
                    lvN.push(["app", e1, e2]);
                }
            }
        }
        exps[n] = lvN;
    }
    return exps;
}

exports.gen = gen;

/*
var _parse = require("./parse.js"),
    parse = _parse.parse, unparse = _parse.unparse;
for (let lvN of gen(["u", "v"], 2)) {
    console.log("======");
    for (let e of lvN) {
        console.log(unparse(e));
    }
}
*/<commit_msg>gen with hasFree<commit_after>"use strict";

// 4 == 3 + 1 // lam
//   == 0 + 1 + 3 == 1 + 1 + 2 == 2 + 1 + 1 == 3 + 1 + 0
function gen(vars, level) {
    var exps = [];
    exps[0] = vars.map(v => ["var", v]);
    
    for (var n = 1; n <= level; n++) {
        var lvN = [];
        for (let e of exps[n - 1]) {
            for (let v of vars) {
                lvN.push(["lam", v, e]);    
            }
        }
        for (let i = 0; i <= n - 1; i++) {
            let j = (n - 1) - i;
            for (let e1 of exps[i]) {
                for (let e2 of exps[j]) {
                    lvN.push(["app", e1, e2]);
                }
            }
        }
        exps[n] = lvN;
    }
    return exps;
}

function hasFree(exp, bound) {
    if (exp[0] == "var") { return ! bound.has(exp[1]); }
    if (exp[0] == "app") { return hasFree(exp[1], bound) || hasFree(exp[2], bound); }
    var newBound = new Set(bound);
    newBound.add(exp[1]);
    return hasFree(exp[2], newBound);
}

exports.gen = gen;

/*
var _parse = require("./parse.js"),
    parse = _parse.parse, unparse = _parse.unparse;
for (let lvN of gen(["u", "v"], 3)) {
    console.log("======");
    for (let e of lvN) {
        //var free = hasFree(e, new Set());
        //console.log(free + " " + unparse(e));
	if (!hasFree(e, new Set())) {
	    console.log(unparse(e));
	}
    }
}
*/
{'fraction_non_alphanumeric': 0.20728534258456202, 'fraction_numerical': 0.025585429314830876, 'mean_word_length': 1.4779806659505907, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3235545', 'n_tokens_mistral': 936, 'n_tokens_neox': 876, 'n_words': 243}