Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This looks great! It has all the essentials and compiles to readable JavaScript, should be a real productivity booster.

Looking at the JavaScript, though, all those anonymous functions can't be very fast.. I wonder if the compiler could try to defunctionalize the output..



The only gratuitous functions I saw were the "case" statement and the "with" statement. The with statement can really only be implemented with that function (though there is something to be said of only defining it once instead of n times). The "case" statement may be gratuitous but it feels like the compiler has a reason for wrapping it in a leakless function wrapper.


For "match", it needs to be an expression for some things so that means wrapping it in a function and returning the result. In the future I'm going to do some optimisation to see if the expression is the last in a function and remove the wrapper. For example:

    return (function() {
        if(b instanceof True) {
            return ifTrue;
        } else if(b instanceof False) {
            return ifFalse;
        }
    })();
Can just become:

    if(b instanceof True) {
        return ifTrue;
    } else if(b instanceof False) {
        return ifFalse;
    }
The output of `with` is pretty gross. Definitely want to hear ideas on how to clean it up :)


Can't you take te same approach ClojureScript took, i.e. to generate a straitforward translation to JavaScript, and then let Google's closure compiler take care of the optimizing thing ?

For instance, for this Roy generated JS:

    var True = function(){};
    var False = function(){};
    var getBool = function(b, ifTrue, ifFalse) {
        return (function() {
            if(b instanceof True) {
                return ifTrue;
            } else if(b instanceof False) {
                return ifFalse;
            }
        })();
    }

The Closure compiler generates:

    var True = function() {
    }, False = function() {
    }, getBool = function(b, c, d) {
      var a;
      b instanceof True ? a = c : b instanceof False && (a = d);
      return a
    };


Roy has the same goal as CoffeeScript - create output that would be similar to how a JS dev would write it. If you use Roy but then decide you don't like it, just take the output and keep going.

I could rely on Closure for optimal performance but what I really want is optimal readability.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: