<commit_before>#!/usr/bin/env node
var ok = require('./oK'); process.stdout.write('oK v' + ok.version + '\n');
var fs = require('fs');
var readline = require('readline');
var conv = require('./convert');

var env = ok.baseEnv();
var rl = readline.createInterface({
	input:  process.stdin,
	output: process.stdout,
	completer: function (line) {
		var m = /[a-z][a-z\d]*$/i.exec(line);
		var prefix = m ? m[0] : '';
		var names = [];
		for (var e = env; e; e = e.p) { // iterate over ancestor environments
			for (var name in e.d) {
				if (name.slice(0, prefix.length) === prefix && names.indexOf(name) < 0) {
					names.push(name);
				}
			}
		}
		return [names, prefix];
	}
});
rl.on('line', function (line) {
	if (line === '\\\\') { process.exit(0); }
	try {
		line.trim() && process.stdout.write(ok.format(ok.run(ok.parse(line), env)) + '\n');
	} catch (err) {
		process.stdout.write(err.message + '\n');
	}
	rl.prompt();
});
rl.on('close', function () { process.stdout.write('\n'); process.exit(0); });
function read(x) {
	// todo
	return conv.tok('');
}
function write(x, y) {
	// todo
	return y;
}
ok.setIO('0:', 2, write);
ok.setIO('0:', 4, write);
ok.setIO('0:', 0, read);
rl.setPrompt(' '); rl.prompt();<commit_msg>implemented some cases of 0:<commit_after>#!/usr/bin/env node
var ok = require('./oK'); process.stdout.write('oK v' + ok.version + '\n');
var fs = require('fs');
var path = require('path');
var readline = require('readline');
var conv = require('./convert');

var env = ok.baseEnv();
var rl = readline.createInterface({
	input:  process.stdin,
	output: process.stdout,
	completer: function (line) {
		var m = /[a-z][a-z\d]*$/i.exec(line);
		var prefix = m ? m[0] : '';
		var names = [];
		for (var e = env; e; e = e.p) { // iterate over ancestor environments
			for (var name in e.d) {
				if (name.slice(0, prefix.length) === prefix && names.indexOf(name) < 0) {
					names.push(name);
				}
			}
		}
		return [names, prefix];
	}
});
rl.on('line', function (line) {
	if (line === '\\\\') { process.exit(0); }
	try {
		line.trim() && process.stdout.write(ok.format(ok.run(ok.parse(line), env)) + '\n');
	} catch (err) {
		process.stdout.write(err.message + '\n');
	}
	rl.prompt();
});
rl.on('close', function () { process.stdout.write('\n'); process.exit(0); });
function str(x) { // convert a k string or symbol to a js string
	var s = x.t === 2 ? x.v : conv.tojs(x);
	if (typeof s !== 'string') { throw Error("ERROR: type"); }
	return s;
}
function read(x) {
	var f = path.resolve(process.cwd(), str(x));
	return conv.tok(fs.statSync(f).isDirectory() ? fs.readdirSync(f) : fs.readFileSync(f, 'utf8').split(/\r?\n/));
}
function write(x, y) {
	var f = path.resolve(process.cwd(), str(x));
	var s = y.t === 2 ? y.v : conv.tojs(y);
	if (Array.isArray(s)) { s = s.map(str).join('\n') + '\n'; }
	if (typeof s !== 'string') { throw Error("ERROR: type"); }
	fs.writeFileSync(f, s);
	return x;
}
for (var i = 0; i < 2; i++) { ok.setIO('0:', i, read ); }
for (var i = 2; i < 6; i++) { ok.setIO('0:', i, write); }
rl.setPrompt(' '); rl.prompt();
{'fraction_non_alphanumeric': 0.24003919007184846, 'fraction_numerical': 0.008491182233834096, 'mean_word_length': 3.497797356828194, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6823589', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1194, 'n_words': 289}