<commit_before>﻿var code = [
['lambda', ['x'], ['+', 'x', ['+', 'y', 'a']]], 3
];

var code2 = [['lambda', ['y'], ['-', 'y', code]], 9];


var code3 = 
[['lambda', ['x'], ['x', 1]], ['lambda', ['y'], ['+', 'a', ['+', 'y', 5]]]]

/*
(let ([x 2])
  (let ([f (lambda (y) (* x y))])
    (let ([x 4])
      (f 3))))
*/

var code4 = 
['let', ['x', 2],
    ['let', ['f', ['lambda', ['y'], ['*', 'x', 'y']]],
        ['let', ['x', 4],
            ['f', 3]
        ]
    ]
];

var index = 0;
var lambdaScopeName = "LAMBDA_";
var letScopeName = "LET_";

var env = {'a' : 5};

function intep(code, cuEnv) {
    console.log('-------BEGIN---')
    console.log(code);
    console.log('---------------')
    console.log(env);
    console.log('---------------')
    console.log(cuEnv);
    console.log('-------END-----')
    if (typeof code === 'string') {
        var tt = cuEnv;
        var re = tt[code];
        while (re === undefined) {
            tt = tt._p;
            re = tt[code];
        }
        return re;
    } else if (typeof code == 'number') {
        return code;
    }

    if (code.length == 3) {
        if (code[0] === 'lambda') {
            code.env = cuEnv;
            return code;
        } else if(code[0] === 'let') {
            index++;
            var tmpScope = cuEnv[letScopeName + index] = {};
            var origin = cuEnv;
            cuEnv = tmpScope;
            cuEnv["_p"] = origin;
            tmpScope[code[1][0]] = intep(code[1][1], cuEnv);
            return intep(code[2], cuEnv);
        } else if (code[0] === '+') {
            return intep(code[1], cuEnv) + intep(code[2], cuEnv);        
        } else if (code[0] === '-') {
            return intep(code[1], cuEnv) - intep(code[2], cuEnv);        
        } else if (code[0] === '*') {
            return intep(code[1], cuEnv) * intep(code[2], cuEnv);        
        } else if (code[0] === '/') {
            return intep(code[1], cuEnv) / intep(code[2], cuEnv);        
        } else {
            throw new Error;
        }
    } else if (code.length == 2) {
        var left = intep(code[0], cuEnv);
        var right = intep(code[1], cuEnv);
        index++;
        var ttenv = left.env;
        var tmpScope = ttenv[lambdaScopeName + index] = {};
        var origin = ttenv;
        ttenv = tmpScope;
        ttenv["_p"] = origin;
        var varName = left[1][0];
        tmpScope[varName] = right;
        return intep(left[2], ttenv);
    } else {
        throw new Error;
    }
}

//var result = intep(code2);
//console.log(result);

console.log(code4);
var result = intep(code4, env);
console.log(result);<commit_msg>add yinwang test<commit_after>﻿var code = [
['lambda', ['x'], ['+', 'x', ['+', 'y', 'a']]], 3
];

var code2 = [['lambda', ['y'], ['-', 'y', code]], 9];


var code3 = 
[['lambda', ['x'], ['x', 1]], ['lambda', ['y'], ['+', 'a', ['+', 'y', 5]]]]

/*
(let ([x 2])
  (let ([f (lambda (y) (* x y))])
    (let ([x 4])
      (f 3))))
*/



var yinTest1 = 
['+', 1, 2];

var yinTest2 = 
['*', 2, 3];

var yinTest3 = 
['*', 2, ['+', 3, 4]];

var yinTest4 = 
['*', ['+', 1, 2], ['+', 3, 4]];

var yinTest5 = 
[['lambda', ['x'], ['*', 2, 'x']], 3];

var yinTest6 = 
['let', ['x', 2], 
	['let', ['f', ['lambda', ['y'], ['*', 'x', 'y']]],
		['f', 3]]];

var yinTest7 = 
['let', ['x', 2],
    ['let', ['f', ['lambda', ['y'], ['*', 'x', 'y']]],
        ['let', ['x', 4],
            ['f', 3]
        ]
    ]
];
var index = 0;
var lambdaScopeName = "LAMBDA_";
var letScopeName = "LET_";

var env = {'a' : 5};

function intep(code, cuEnv) {
    //console.log('-------BEGIN---')
    //console.log(code);
    //console.log('---------------')
    //console.log(env);
    //console.log('---------------')
    //console.log(cuEnv);
    //console.log('-------END-----')
    if (typeof code === 'string') {
        var tt = cuEnv;
        var re = tt[code];
        while (re === undefined) {
            tt = tt._p;
            re = tt[code];
        }
        return re;
    } else if (typeof code == 'number') {
        return code;
    }

    if (code.length == 3) {
        if (code[0] === 'lambda') {
            code.env = cuEnv;
            return code;
        } else if(code[0] === 'let') {
            index++;
            var tmpScope = {};
            var origin = cuEnv;
            cuEnv = tmpScope;
            cuEnv["_p"] = origin;
            tmpScope[code[1][0]] = intep(code[1][1], cuEnv);
            return intep(code[2], cuEnv);
        } else if (code[0] === '+') {
            return intep(code[1], cuEnv) + intep(code[2], cuEnv);        
        } else if (code[0] === '-') {
            return intep(code[1], cuEnv) - intep(code[2], cuEnv);        
        } else if (code[0] === '*') {
            return intep(code[1], cuEnv) * intep(code[2], cuEnv);        
        } else if (code[0] === '/') {
            return intep(code[1], cuEnv) / intep(code[2], cuEnv);        
        } else {
            throw new Error;
        }
    } else if (code.length == 2) {
        var left = intep(code[0], cuEnv);
        var right = intep(code[1], cuEnv);
        index++;
        var ttenv = left.env;
        var tmpScope = {};
        var origin = ttenv;
        ttenv = tmpScope;
        ttenv["_p"] = origin;
        var varName = left[1][0];
        tmpScope[varName] = right;
        return intep(left[2], ttenv);
    } else {
        throw new Error;
    }
}

//var result = intep(code2);
//console.log(result);
function r2(code) {
	console.log(intep(code, env));
}

r2(yinTest1);
r2(yinTest2);
r2(yinTest3);
r2(yinTest4);
r2(yinTest5);
r2(yinTest6);
r2(yinTest7);
{'fraction_non_alphanumeric': 0.246197888709966, 'fraction_numerical': 0.021828591876901057, 'mean_word_length': 1.8318135764944277, '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': '3155387', 'n_tokens_mistral': 2120, 'n_tokens_neox': 2049, 'n_words': 483}