<commit_before>//for clients to override

function focus_callback() {
}

//functional functions

function cleanCode(code) {
  return code.replace(/^\n/, "").replace(/\n*$/, "").replace(/[ \t]*\n/g, "\n").replace(/\s*$/, "");
}

function check(result) {
  //console.log(typeof(result), result);
  if (result == undefined) {
    return false;
  }
  if (typeof(result) == "object" && result.toString && result.toString() == "#<undef>") {
    return false;
  }
  return true;
}

//Biwascheme

var biwascheme = new BiwaScheme.Interpreter( function(e){
  console.log(e.message);
});

function resetTopEnv() {
  BiwaScheme.TopEnv = {};
  BiwaScheme.TopEnv["define"] = new BiwaScheme.Syntax("define");
  BiwaScheme.TopEnv["begin"] = new BiwaScheme.Syntax("begin");
  BiwaScheme.TopEnv["quote"] = new BiwaScheme.Syntax("quote");
  BiwaScheme.TopEnv["lambda"] = new BiwaScheme.Syntax("lambda");
  BiwaScheme.TopEnv["if"] = new BiwaScheme.Syntax("if");
  BiwaScheme.TopEnv["set!"] = new BiwaScheme.Syntax("set!");
}

editorOf = {};

function makeEditable(editable_string) {

  var $target = $("#" + editable_string);
  if (!$target[0]) {
    throw "$" + editable_string + " did not match anything";
  }
  
  var code = cleanCode($target.text());
  
  $target.empty();
  
  var editor = CodeMirror($target[0], {
    'value': code,
    'matchBrackets': true
  });
  
  editorOf[editable_string] = editor;
}

function linkEval(editable_string, output_string, deps) {

  var e = editorOf[editable_string];

  e.setOption('onBlur', function() {
    result = biwascheme.evaluate(e.getValue());
    $("#" + output_string).empty().append($("<span>" + result + "</span>"));
  });
}

function evaluate(target_string) {
  
  if (s.deps) {
    for (var i = 0; i < s.deps.length; i++) {
      evaluate(s.deps[i]);
    }
  }
  try {
    return biwascheme.evaluate(sOf[target_string].getCode());
  }
  catch (e) {
    return;<commit_msg>introduce $h<commit_after>//for clients to override

function focus_callback() {
}

//functional functions

function cleanCode(code) {
  return code.replace(/^\n/, "").replace(/\n*$/, "").replace(/[ \t]*\n/g, "\n").replace(/\s*$/, "");
}

function check(result) {
  //console.log(typeof(result), result);
  if (result == undefined) {
    return false;
  }
  if (typeof(result) == "object" && result.toString && result.toString() == "#<undef>") {
    return false;
  }
  return true;
}

//Biwascheme

var biwascheme = new BiwaScheme.Interpreter( function(e){
  console.log(e.message);
});

function resetTopEnv() {
  BiwaScheme.TopEnv = {};
  BiwaScheme.TopEnv["define"] = new BiwaScheme.Syntax("define");
  BiwaScheme.TopEnv["begin"] = new BiwaScheme.Syntax("begin");
  BiwaScheme.TopEnv["quote"] = new BiwaScheme.Syntax("quote");
  BiwaScheme.TopEnv["lambda"] = new BiwaScheme.Syntax("lambda");
  BiwaScheme.TopEnv["if"] = new BiwaScheme.Syntax("if");
  BiwaScheme.TopEnv["set!"] = new BiwaScheme.Syntax("set!");
}

editorOf = {};

function $h(s) {
  ret = $("#" + s);
  if (!ret[0]) {
    throw "#" + s + " did not match anything";
  } else {
    return ret;
  }
}

function makeEditable(editable) {

  var $e = $h(editable);
  var code = cleanCode($e.text());
  
  $e.empty();
  
  var editor = CodeMirror($e[0], {
    'value': code,
    'matchBrackets': true
  });
  
  editorOf[editable] = editor;
}

function linkEval(editable, output, deps) {

  var e = editorOf[editable];

  e.setOption('onBlur', function() {
    result = biwascheme.evaluate(e.getValue());
    $h(output).empty().append($("<span>" + result + "</span>"));
  });
}

function evaluate(target_string) {
  
  if (s.deps) {
    for (var i = 0; i < s.deps.length; i++) {
      evaluate(s.deps[i]);
    }
  }
  try {
    return biwascheme.evaluate(sOf[target_string].getCode());
  }
  catch (e) {
    return;
{'fraction_non_alphanumeric': 0.1998416050686378, 'fraction_numerical': 0.0015839493136219642, 'mean_word_length': 3.784090909090909, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5117901', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1361, 'n_words': 251}