Seeing-is-believing


#1

yesterday I have found this package https://atom.io/packages/seeing-is-believing
and now i wonder if its possible to have it for js/coffeescript too?


#2

I like that idea a lot. Would be really helpful!

It’s probably possible for JS/CS and whatever other scripting languages, but the mentioned package for Ruby requires the seeing-is-believing gem installed as a dependency, so a similar evaluation engine will probably be needed for each of those other languages as well.
No idea if there is a similar node module that can be included by a package like this.

Edit:
Looks like it can’t be that hard:

Taken from this guy’s example:

var timer;
var buffer = "";

function evalSwitchClicked(e) {
    if (e.checked) {
        evalStart();
    } else {
        evalStop();
    }
}

function evalStart() {
    var o = document.getElementById("eval_time");
    timer = setTimeout(timerHandler, o.value);
}

function evalStop() {
    clearTimeout(timer);
}

function timerHandler() {
    clearTimeout(timer);
    var sw = document.getElementById("eval_switch");
    if (sw.checked) {
        evalOnce();
        evalStart();
    }
}

function evalOnce() {
    try {
        var code = document.getElementById("code").value;
        var result = eval(code);
        buffer += result;
        flush();
    } catch (ex) {
        buffer = ex;
        flush();
    }
}

function clear()  {
    var out = document.getElementById("out");
    out.value = "";
}

function print(str)  {
    buffer += str + "\n";
}

function flush()  {
    var out = document.getElementById("out");
    out.value = buffer;
    buffer = "";
}

// [...]

(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {evalSwitchClicked(this)
};}}}})

#3

not sure if such eval can guess the type of variables exactly to fill the function to be evaluated with meaningful or type correct data. i bet we are all not writing functions which do not take any parameter :wink:

the evaluation from the site is triggered constantly, what i like in general but it looks like the eval trigger does not wait for results. its just luck that the example code is executed in less than 200ms :smile:

this feature would be, at least to me, the biggest selling point :smiley:


#4

Well, it was meant as a starting point.
Maybe somebody has already been working on something similar or can give you a few tips where else to start…


#5

http://rsense.github.io/
another great tool. again for ruby.

i have already an idea but not sure if an external nodejs process is needed or if atom can handle it.
but ast navigation is the thing to start with. doing more research.