Hacker News new | comments | show | ask | jobs | submit login

Callbacks are different than gotos in that they are aren't even remotely close to gotos.

The analogy is that callbacks create non-linear control flow. Using a monadic syntax like in Roy, we can easily have callbacks without having them look non-linear:

    let deferred = {
      return: \x ->
        let d = $.Deferred ()
        d.resolve x
        d.promise ()
      bind: \x f -> x.pipe f

    let v = do deferred
      hello <- $.ajax 'examples/helloworld.roy'
      alias <- $.ajax 'examples/alias.roy'
      return (hello ++ alias)

    v.done console.log
Which compiles into continuation passing:

    var deferred = {
        "return": function(x) {
            var d = $.Deferred();
            return d.promise();
        "bind": function(x, f) {
            return x.pipe(f);
    var v = (function(){
        var __monad__ = deferred;
        return __monad__.bind($.ajax('examples/helloworld.roy'), function(hello) {
            return __monad__.bind($.ajax('examples/alias.roy'), function(alias) {
                return __monad__.return((hello + alias));
Anyway, continuations (with call/cc) are definitely a controlled form of goto. Take a look at an example from Paul Graham:


      (lambda (goto)
        (letrec ((start
                  (lambda ()
                    (print "start")
                    (goto next)))
                  (lambda ()
                    (print "froz")
                    (goto last)))
                  (lambda ()
                    (print "next")
                    (goto froz)))
                  (lambda ()
                    (print "last")
                    (+ 3 4))))

All of structured programming consists of various controlled forms of goto.

Yesterday, I found an email from Jon Callas where he was giving advice on where SAML falls in the Chomsky hierarchy of languages:

"If it has backwards gotos in any form, it's Turing-complete. Loops, recursion, etc. are backwards gotos. If-then-else is a forward goto."

I hadn't ever thought of things that way, but I thought it was interesting.

Once you've worked in assembly language, you realize everything is just another form of jmp.

That's the point of the article, though: callbacks don't offer enough structure to effectively reason about.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact