<commit_before>"use strict";
define(["bacon", "jquery.console", "jq-console"], function(Bacon) {
  var welcomeMessage = "Welcome to Turtle Roy.\nTry this: repeat 360 (sequence[fd 1, lt 1])\nOr try one of the examples below.\n"
  var promptLabel = 'λ> '
  function fmt(value, className) {
    return {msg: value, className: "jqconsole-" + className};
  }

  function fmtValue(value) { return fmt(value, "value"); }
  function fmtType(value) { return fmt(value, "type"); }
  function fmtError(value) { return fmt(value, "error"); }

  function init(consoleElement, roy) {
    var history = new Bacon.Bus()
    var error = new Bacon.Bus()
    var skipHistory
    var cs = consoleElement.jqconsole(welcomeMessage, promptLabel)
    setInterval(function() {$(".jqconsole-cursor").toggleClass("blink")}, 500)
    function sendToConsole(message) {
      message.forEach(function(msg) {
        cs.Write(msg.msg + '\n', msg.className);
      })
    }
    function syncEvalAsMessage(line) {
      var parts = line.split(" ");

      switch (parts[0]) {
      case ":t":
        var term = parts[1]
        var env = roy.royEnv(term)
        if (env) {
          return [fmtType(env)];
        } else {
          return [fmtError(term + " is not defined.")];
        }

      case ":c":
        try {
          var code = parts.slice(1).join(" ");
          var compiled = roy.compileRoy(code)
          return [fmt(compiled.output, "code")];
        } catch(e) {
          return [fmtError(e.toString())];
        }

      default:
        try {
          var evaled = roy.evalRoy(line);
          if (skipHistory) {
            skipHistory = false
          } else {
            history.push(line)
          }
          error.push("")
          if (evaled != undefined && evaled.result != null) {
            return [fmtValue(JSON.stringify(evaled.result))];
          } else {
            return [];
          }
        } catch(e) {
          var msg = fmtError(e.toString())
          error.push(msg.msg)
          return [msg];
        }
      }
    }
    function prompt() {
      cs.Prompt(true, function(line) {
        var response = syncEvalAsMessage(line)
        sendToConsole(response)
        prompt()
      })  
    }
    prompt()
    return {
      history: history,
      paste: function(text) {
      },
      error: error.toProperty(),
      print: function(line) {
      },
      skipHistory: function() {
        skipHistory = true
      }
    }
  }

  function init_old(consoleElement, roy) {
    var history = new Bacon.Bus()
    var error = new Bacon.Bus()
    var sendToConsole;
    var skipHistory

    var controller = consoleElement.console({
      promptLabel: 'λ> ',
      autofocus: true,<commit_msg>eval as message stream<commit_after>"use strict";
define(["bacon", "jquery.console", "jq-console"], function(Bacon) {
  var welcomeMessage = "Welcome to Turtle Roy.\nTry this: repeat 360 (sequence[fd 1, lt 1])\nOr try one of the examples below.\n"
  var promptLabel = 'λ> '
  function fmt(value, className) {
    return {msg: value, className: "jqconsole-" + className};
  }

  function fmtValue(value) { return fmt(value, "value"); }
  function fmtType(value) { return fmt(value, "type"); }
  function fmtError(value) { return fmt(value, "error"); }

  function init(consoleElement, roy) {
    var history = new Bacon.Bus()
    var error = new Bacon.Bus()
    var skipHistory
    var cs = consoleElement.jqconsole(welcomeMessage, promptLabel)
    setInterval(function() {$(".jqconsole-cursor").toggleClass("blink")}, 500)
    function sendToConsole(msg) {
      cs.Write(msg.msg + '\n', msg.className);
    }
    function evalAsMessageStream(line) {
      var parts = line.split(" ");

      switch (parts[0]) {
      case ":t":
        var term = parts[1]
        var env = roy.royEnv(term)
        if (env) {
          return Bacon.once(fmtType(env));
        } else {
          return Bacon.once(fmtError(term + " is not defined."));
        }

      case ":c":
        try {
          var code = parts.slice(1).join(" ");
          var compiled = roy.compileRoy(code)
          return Bacon.once(fmt(compiled.output, "code"));
        } catch(e) {
          return Bacon.once(fmtError(e.toString()));
        }

      default:
        try {
          var evaled = roy.evalRoy(line);
          if (skipHistory) {
            skipHistory = false
          } else {
            history.push(line)
          }
          error.push("")
          if (evaled != undefined && evaled.result != null) {
            return Bacon.once(fmtValue(JSON.stringify(evaled.result)));
          } else {
            return Bacon.once();
          }
        } catch(e) {
          var msg = fmtError(e.toString())
          error.push(msg.msg)
          return Bacon.once(msg);
        }
      }
    }
    function prompt() {
      cs.Prompt(true, function(line) {
        var response = evalAsMessageStream(line)
        response.onValue(sendToConsole)
        response.onEnd(prompt)
      })  
    }
    prompt()
    return {
      history: history,
      paste: function(text) {
      },
      error: error.toProperty(),
      print: function(line) {
      },
      skipHistory: function() {
        skipHistory = true
      }
    }
  }

  function init_old(consoleElement, roy) {
    var history = new Bacon.Bus()
    var error = new Bacon.Bus()
    var sendToConsole;
    var skipHistory

    var controller = consoleElement.console({
      promptLabel: 'λ> ',
      autofocus: true,
{'fraction_non_alphanumeric': 0.13546977421704298, 'fraction_numerical': 0.004005826656955572, 'mean_word_length': 2.101637492941841, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 7, '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': '344563', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1615, 'n_words': 384}