Fork me on GitHub

PogoScript to JavaScript Examples

Side-by-side examples of PogoScript compiling to JavaScript.

Arrays

array one = [1, "two"]

array two = [
    3
    "four"
]
var arrayOne, arrayTwo;

arrayOne = [ 1, "two" ];

arrayTwo = [ 3, "four" ];

Blocks Preserve Self

person = {

    name = 'Man Ray'

    say hi later() =
        set
            console. log "my name is #(self.name)"
        timeout 123

}

not using an arrow
    means (self) is not always (this)

using an arrow =>
    means (self) is always (this)
var person;

person = {
    name: "Man Ray",
    sayHiLater: function() {
        var self = this;
        return setTimeout(function() {
            return console.log("my name is " + self.name);
        }, 123);
    }
};

notUsingAnArrow(function() {
    return meansIsNotAlways(self, this);
});

usingAnArrow(function() {
    var self = this;
    return meansIsAlways(self, this);
});

Closures

map each @(file) in (files) into @{ resolve (file) }

map each @(file) in (files) into
    resolve (file)
mapEachInInto(files, function(file) {
    return resolve(file);
});

mapEachInInto(files, function(file) {
    return resolve(file);
});

Declaring Functions

one lower than (n) = n - 1

one higher than (n) =
    n + 1

either (thing) or (other) =
    thing || other

end of the line () =
    ok then()
var oneLowerThan, oneHigherThan, eitherOr, endOfTheLine;

oneLowerThan = function(n) {
    return n - 1;
};

oneHigherThan = function(n) {
    return n + 1;
};

eitherOr = function(thing, other) {
    return thing || other;
};

endOfTheLine = function() {
    return okThen();
};

Dsl

describe 'a horse'
    before
      self.horse = new (Horse)

    context 'that is dead'
        before
            self.horse.kill()
  
        it 'should not move'
            self.horse.should not move()
describe("a horse", function() {
    before(function() {
        return self.horse = new Horse();
    });
    return context("that is dead", function() {
        before(function() {
            return self.horse.kill();
        });
        return it("should not move", function() {
            return self.horse.shouldNotMove();
        });
    });
});

Event Emitter

EventEmitter = require('events').EventEmitter

shouter = new (EventEmitter)

shouter.on 'shout'
    console.log "calm down"

shouter.emit 'shout'
var EventEmitter, shouter;

EventEmitter = require("events").EventEmitter;

shouter = new EventEmitter();

shouter.on("shout", function() {
    return console.log("calm down");
});

shouter.emit("shout");

Factorial (Iterative)

factorial (n) =
    x = 1
    for (i = 2, i <= n, i := i + 1)
        x := x * i

    x
var factorial;

factorial = function(n) {
    var x, i;
    x = 1;
    for (i = 2; i <= n; i = i + 1) {
        x = x * i;
    }
    return x;
};

Factorial (Recursive)

factorial (n) =
    if (n == 0)
        1
    else
        n * factorial (n - 1)
var factorial;

factorial = function(n) {
    if (n === 0) {
        return 1;
    } else {
        return n * factorial(n - 1);
    }
};

Fibonacci

fib (i) =
    if ((i == 0) || (i == 1))
        1
    else
        fib (i - 1) + fib (i - 2)
var fib;

fib = function(i) {
    if (i === 0 || i === 1) {
        return 1;
    } else {
        return fib(i - 1) + fib(i - 2);
    }
};

For

for (n = 0, n < 10, n := n + 1)
    console. log (n)
var n;

for (n = 0; n < 10; n = n + 1) {
    console.log(n);
}

For Each

for each @(fruit) in (basket)
    gobble(fruit)
var gen1_items, gen2_i, fruit;

gen1_items = basket;

for (gen2_i = 0; gen2_i < gen1_items.length; ++gen2_i) {
    fruit = gen1_items[gen2_i];
    gobble(fruit);
}

Function Calls

y = compute some value from (z) and return it

md5 hash (read all text from file "sample.txt")
var y;

y = computeSomeValueFromAndReturnIt(z);

md5Hash(readAllTextFromFile("sample.txt"));

Functions Without Arguments

update page()
hungry = is lunch time()
var hungry;

updatePage();

hungry = isLunchTime();

If

if (wind speed > 20)
    console. log "gone kitesurfing!"
else
    console. log "no wind, programming"
if (windSpeed > 20) {
    console.log("gone kitesurfing!");
} else {
    console.log("no wind, programming");
}

List Comprehensions

mapped = [x * x, where: x <- [1, 2, 3]]

filtered = [x, where: x <- [1, 2, 3], x > 1]

both = [x * y, where: x <- [1, 2, 3], y <- [4, 5, 6]]
var mapped, filtered, both;

mapped = function() {
    var gen1_results, gen2_items, gen3_i, x;
    gen1_results = [];
    gen2_items = [ 1, 2, 3 ];
    for (gen3_i = 0; gen3_i < gen2_items.length; ++gen3_i) {
        x = gen2_items[gen3_i];
        gen1_results.push(x * x);
    }
    return gen1_results;
}();

filtered = function() {
    var gen4_results, gen5_items, gen6_i, x;
    gen4_results = [];
    gen5_items = [ 1, 2, 3 ];
    for (gen6_i = 0; gen6_i < gen5_items.length; ++gen6_i) {
        x = gen5_items[gen6_i];
        if (x > 1) {
            gen4_results.push(x);
        }
    }
    return gen4_results;
}();

both = function() {
    var gen7_results, gen8_items, gen9_i, x, gen10_items, gen11_i, y;
    gen7_results = [];
    gen8_items = [ 1, 2, 3 ];
    for (gen9_i = 0; gen9_i < gen8_items.length; ++gen9_i) {
        x = gen8_items[gen9_i];
        gen10_items = [ 4, 5, 6 ];
        for (gen11_i = 0; gen11_i < gen10_items.length; ++gen11_i) {
            y = gen10_items[gen11_i];
            gen7_results.push(x * y);
        }
    }
    return gen7_results;
}();

Method Calls

file = open file "README.md"
file. read line()

open file "README.md". read line()
var file;

file = openFile("README.md");

file.readLine();

openFile("README.md").readLine();

Method Chains

list. map @(i) into
    i + 1
.select @(i) if
    i < 5
.each @(i) do
    console. log (i)
list.mapInto(function(i) {
    return i + 1;
}).selectIf(function(i) {
    return i < 5;
}).eachDo(function(i) {
    return console.log(i);
});

Multiline Functions

item = 0

do
    print (item)
    item := item + 1
while @{ item < 10 }
var item;

item = 0;

doWhile(function() {
    print(item);
    return item = item + 1;
}, function() {
    return item < 10;
});

Objects

address = {
    street = "Fake Street"
    post code = "123 ABC"
}
var address;

address = {
    street: "Fake Street",
    postCode: "123 ABC"
};

Operators

total height = header + (item * count) + footer

definitely = true @and true

maybe = false @or true

no way = (definitely) not

(p1) plus (p2) = { x = p1.x + p2.x, y = p1.y + p2.y }

a = { x = 1, y = 2 }
b = { x = 3, y = 4 }
a @plus b
var totalHeight, definitely, maybe, noWay, plus, a, b;

totalHeight = header + item * count + footer;

definitely = true && true;

maybe = false || true;

noWay = !definitely;

plus = function(p1, p2) {
    return {
        x: p1.x + p2.x,
        y: p1.y + p2.y
    };
};

a = {
    x: 1,
    y: 2
};

b = {
    x: 3,
    y: 4
};

plus(a, b);

Optional Arguments

connect to mysql database (address: "1.2.3.4", port: 3307)

connect to mysql database (readonly: true)
connectToMysqlDatabase({
    address: "1.2.3.4",
    port: 3307
});

connectToMysqlDatabase({
    readonly: true
});

Options

connect to (port: 3306, host: "127.0.0.1") =
    console.log "connecting to #(host):#(port)"
var connectTo;

connectTo = function(gen1_options) {
    var port, host;
    port = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "port") && gen1_options.port !== void 0 ? gen1_options.port : 3306;
    host = gen1_options !== void 0 && Object.prototype.hasOwnProperty.call(gen1_options, "host") && gen1_options.host !== void 0 ? gen1_options.host : "127.0.0.1";
    return console.log("connecting to " + host + ":" + port);
};

Regular Expressions

"hot dog".replace r/d.g/ "potato"

"FOO".match r/foo/gi
"hot dog".replace(/d.g/, "potato");

"FOO".match(/foo/gi);

Splat Arguments

foo (args, ...) =
     print (args)

foo 1 [2, 3] ... [4, 5] ... 6
var foo;

foo = function() {
    var args = Array.prototype.slice.call(arguments, 0, arguments.length);
    return print(args);
};

foo.apply(null, [ 1 ].concat([ 2, 3 ]).concat([ 4, 5 ]).concat([ 6 ]));

Strings

'meet you at Jayne''s place'

alan kay = "The best way to predict the future
            is to invent it."

mood = "happy"
announce "Feeling #(mood) today"
var alanKay, mood;

"meet you at Jayne's place";

alanKay = "The best way to predict the future\nis to invent it.";

mood = "happy";

announce("Feeling " + mood + " today");

Try Catch

try
    something messy()
catch (ex)
    console.log "it went horribly wrong"
finally
    better clean up()
try {
    somethingMessy();
} catch (ex) {
    console.log("it went horribly wrong");
} finally {
    betterCleanUp();
}

Variables

height = 1025

height :=
    n = 10
    (n * n * n) + 25
var height;

height = 1025;

height = function() {
    var n;
    n = 10;
    return n * n * n + 25;
}();

Web Server

http = require 'http'
http. create server @(request, response)
    response.end "Hello World\n"
.listen 1337
var http;

http = require("http");

http.createServer(function(request, response) {
    return response.end("Hello World\n");
}).listen(1337);

When

is (expected) (action) =
    action if (actual) matched =
        if (expected == actual)
            action

otherwise (action) =
    action if (actual) matched =
        action

when (actual, cases) =
    for each @(action if matched) in (cases)
        action = action if (actual) matched
        if (action)
            return (action ())

print (args, ...) = console.log (args, ...)

x = 2

when (x) [
    is 0
        print "x is zero"

    is 1
        print "x is one"

    otherwise
        print "x is not zero or one"
]
var is, otherwise, when, print, x;

is = function(expected, action) {
    var actionIfMatched;
    return actionIfMatched = function(actual) {
        if (expected === actual) {
            return action;
        }
    };
};

otherwise = function(action) {
    var actionIfMatched;
    return actionIfMatched = function(actual) {
        return action;
    };
};

when = function(actual, cases) {
    var gen1_items, gen2_i, gen3_forResult;
    gen1_items = cases;
    for (gen2_i = 0; gen2_i < gen1_items.length; ++gen2_i) {
        gen3_forResult = void 0;
        if (function(gen2_i) {
            var actionIfMatched, action;
            actionIfMatched = gen1_items[gen2_i];
            action = actionIfMatched(actual);
            if (action) {
                gen3_forResult = action();
                return true;
            }
        }(gen2_i)) {
            return gen3_forResult;
        }
    }
    return void 0;
};

print = function() {
    var args = Array.prototype.slice.call(arguments, 0, arguments.length);
    var gen4_o;
    gen4_o = console;
    return gen4_o.log.apply(gen4_o, args);
};

x = 2;

when(x, [ is(0, function() {
    return print("x is zero");
}), is(1, function() {
    return print("x is one");
}), otherwise(function() {
    return print("x is not zero or one");
}) ]);

Async Calls

web page = http.get! "http://www.interesting.com"
scrape facts from (web page)
http.get("http://www.interesting.com", function(gen1_error, gen2_asyncResult) {
    var webPage;
    if (gen1_error) {
        continuation(gen1_error);
    } else {
        try {
            webPage = gen2_asyncResult;
            continuation(void 0, scrapeFactsFrom(webPage));
        } catch (gen3_exception) {
            continuation(gen3_exception);
        }
    }
});

Async Continuations

current continuation (callback) =
    continuation () =
        callback (nil, continuation)

    callback (nil, continuation)

n = 0

cont = current continuation!

console.log (n)
n := n + 1

if (n < 10)
    cont ()
var currentContinuation, n;

currentContinuation = function(callback) {
    var continuation;
    continuation = function() {
        callback(void 0, continuation);
    };
    callback(void 0, continuation);
};

n = 0;

currentContinuation(function(gen1_error, gen2_asyncResult) {
    var cont;
    if (gen1_error) {
        continuation(gen1_error);
    } else {
        try {
            cont = gen2_asyncResult;
            console.log(n);
            n = n + 1;
            if (n < 10) {
                continuation(void 0, cont());
            } else {
                continuation();
            }
        } catch (gen3_exception) {
            continuation(gen3_exception);
        }
    }
});

Async Coroutines

last yield continuation = nil
last result continuation = nil

yield (n, yield continuation) =
    last yield continuation := yield continuation
    last result continuation (nil, n)

coroutine (block) =
    run (result continuation) =
        last result continuation := result continuation

        if (last yield continuation)
            last yield continuation ()
        else
            block
                last yield continuation := nil
                last result continuation := nil

strings = coroutine
    yield! 1
    yield! 2
    yield! 3

console.log (strings!)
console.log (strings!)
console.log (strings!)
console.log 'finished'
var lastYieldContinuation, lastResultContinuation, yield, coroutine, strings;

lastYieldContinuation = void 0;

lastResultContinuation = void 0;

yield = function(n, yieldContinuation) {
    lastYieldContinuation = yieldContinuation;
    return lastResultContinuation(void 0, n);
};

coroutine = function(block) {
    var run;
    return run = function(resultContinuation) {
        lastResultContinuation = resultContinuation;
        if (lastYieldContinuation) {
            return lastYieldContinuation();
        } else {
            return block(function() {
                lastYieldContinuation = void 0;
                return lastResultContinuation = void 0;
            });
        }
    };
};

strings = coroutine(function(continuation) {
    var gen1_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    yield(1, function(gen2_error, gen3_asyncResult) {
        if (gen2_error) {
            continuation(gen2_error);
        } else {
            try {
                gen3_asyncResult;
                yield(2, function(gen4_error, gen5_asyncResult) {
                    if (gen4_error) {
                        continuation(gen4_error);
                    } else {
                        try {
                            gen5_asyncResult;
                            yield(3, continuation);
                        } catch (gen6_exception) {
                            continuation(gen6_exception);
                        }
                    }
                });
            } catch (gen7_exception) {
                continuation(gen7_exception);
            }
        }
    });
});

strings(function(gen8_error, gen9_asyncResult) {
    if (gen8_error) {
        continuation(gen8_error);
    } else {
        try {
            console.log(gen9_asyncResult);
            strings(function(gen10_error, gen11_asyncResult) {
                if (gen10_error) {
                    continuation(gen10_error);
                } else {
                    try {
                        console.log(gen11_asyncResult);
                        strings(function(gen12_error, gen13_asyncResult) {
                            if (gen12_error) {
                                continuation(gen12_error);
                            } else {
                                try {
                                    console.log(gen13_asyncResult);
                                    continuation(void 0, console.log("finished"));
                                } catch (gen14_exception) {
                                    continuation(gen14_exception);
                                }
                            }
                        });
                    } catch (gen15_exception) {
                        continuation(gen15_exception);
                    }
                }
            });
        } catch (gen16_exception) {
            continuation(gen16_exception);
        }
    }
});

Async For

for (n = 0, n < 3, n := n + 1)
    send letter! (n)

all letters sent()
var gen1_asyncFor;

gen1_asyncFor = function(test, incr, loop, cb) {
    try {
        var testAndLoop = function() {
            test(function(error, anotherLoop) {
                if (error) {
                    cb(error);
                } else {
                    if (anotherLoop) {
                        loop(incrTestAndLoop);
                    } else {
                        cb();
                    }
                }
            });
        };
        var incrTestAndLoop = function(error) {
            if (error) {
                cb(error);
            } else {
                incr(function(error) {
                    if (error) {
                        cb(error);
                    } else {
                        testAndLoop();
                    }
                });
            }
        };
        testAndLoop();
    } catch (error) {
        cb(error);
    }
};

(function(continuation) {
    var gen2_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    var n;
    n = 0;
    gen1_asyncFor(function(continuation) {
        var gen3_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
        continuation = arguments[arguments.length - 1];
        if (!(continuation instanceof Function)) {
            throw new Error("asynchronous function called synchronously");
        }
        continuation(void 0, n < 3);
    }, function(continuation) {
        var gen4_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
        continuation = arguments[arguments.length - 1];
        if (!(continuation instanceof Function)) {
            throw new Error("asynchronous function called synchronously");
        }
        continuation(void 0, n = n + 1);
    }, function(continuation) {
        var gen5_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
        continuation = arguments[arguments.length - 1];
        if (!(continuation instanceof Function)) {
            throw new Error("asynchronous function called synchronously");
        }
        sendLetter(n, continuation);
    }, continuation);
})(function(gen6_error, gen7_asyncResult) {
    if (gen6_error) {
        continuation(gen6_error);
    } else {
        try {
            gen7_asyncResult;
            continuation(void 0, allLettersSent());
        } catch (gen8_exception) {
            continuation(gen8_exception);
        }
    }
});

Async Fork

fs = require 'fs'

fork (block) = block @{}

fork
    console.log "reading contents of file #(__filename)"
    contents = fs.read file (__filename,  'utf-8')!
    console.log ("contents of #(__filename):")
    process.stdout.write (contents)

console.log 'processing other stuff'
var fs, fork;

fs = require("fs");

fork = function(block) {
    return block(function() {});
};

fork(function(continuation) {
    var gen1_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    console.log("reading contents of file " + __filename);
    fs.readFile(__filename, "utf-8", function(gen2_error, gen3_asyncResult) {
        var contents;
        if (gen2_error) {
            continuation(gen2_error);
        } else {
            try {
                contents = gen3_asyncResult;
                console.log("contents of " + __filename + ":");
                continuation(void 0, process.stdout.write(contents));
            } catch (gen4_exception) {
                continuation(gen4_exception);
            }
        }
    });
});

console.log("processing other stuff");

Async Futures

a = fs.stat? 'a.txt'
b = fs.stat? 'b.txt'

console.log "size of a.txt is #(a!.size)"
console.log "size of b.txt is #(b!.size)"
var gen1_future, a, b;

gen1_future = function(action) {
    var operationComplete = false;
    var operationError, operationResult;
    var futureCallbacks = [];
    function callback(error, result) {
        operationComplete = true;
        operationError = error;
        operationResult = result;
        for (var n = 0; n < futureCallbacks.length; n++) {
            futureCallbacks[n](operationError, operationResult);
        }
    }
    try {
        action(callback);
    } catch (error) {
        operationComplete = true;
        operationError = error;
    }
    return function(callback) {
        if (operationComplete) {
            callback(operationError, operationResult);
        } else {
            futureCallbacks.push(callback);
        }
    };
};

a = gen1_future(function(continuation) {
    fs.stat("a.txt", continuation);
});

b = gen1_future(function(continuation) {
    fs.stat("b.txt", continuation);
});

a(function(gen2_error, gen3_asyncResult) {
    if (gen2_error) {
        continuation(gen2_error);
    } else {
        try {
            console.log("size of a.txt is " + gen3_asyncResult.size);
            b(function(gen4_error, gen5_asyncResult) {
                if (gen4_error) {
                    continuation(gen4_error);
                } else {
                    try {
                        continuation(void 0, console.log("size of b.txt is " + gen5_asyncResult.size));
                    } catch (gen6_exception) {
                        continuation(gen6_exception);
                    }
                }
            });
        } catch (gen7_exception) {
            continuation(gen7_exception);
        }
    }
});

Async If

if ((intruders) are dangerous)
    kill! (intruders)
else
    call the cops about! (intruders)

keep watch!
var gen1_asyncIfElse;

gen1_asyncIfElse = function(condition, thenBody, elseBody, cb) {
    if (condition) {
        try {
            thenBody(cb);
        } catch (ex) {
            cb(ex);
        }
    } else {
        try {
            elseBody(cb);
        } catch (ex) {
            cb(ex);
        }
    }
};

gen1_asyncIfElse(areDangerous(intruders), function(continuation) {
    var gen2_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    kill(intruders, continuation);
}, function(continuation) {
    var gen3_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    callTheCopsAbout(intruders, continuation);
}, function(gen4_error, gen5_asyncResult) {
    if (gen4_error) {
        continuation(gen4_error);
    } else {
        try {
            gen5_asyncResult;
            keepWatch(continuation);
        } catch (gen6_exception) {
            continuation(gen6_exception);
        }
    }
});

Async Try Catch

record = nil

try
    database = connect to the database!
    record := database.query!
catch (error)
    exit the program because of (error)!
finally
    database.close!

console.log("RECORD FOUND: #(record)")
var gen1_asyncTry, record;

gen1_asyncTry = function(body, catchBody, finallyBody, cb) {
    var callbackCalled = false;
    var callback = function(error, result) {
        if (!callbackCalled) {
            callbackCalled = true;
            cb(error, result);
        }
    };
    try {
        body(function(error, result) {
            if (error) {
                if (finallyBody && catchBody) {
                    try {
                        catchBody(error, function(error, result) {
                            try {
                                finallyBody(function(finallyError) {
                                    callback(finallyError || error, finallyError || error ? undefined : result);
                                });
                            } catch (error) {
                                callback(error);
                            }
                        });
                    } catch (error) {
                        try {
                            finallyBody(function(finallyError) {
                                callback(finallyError || error);
                            });
                        } catch (error) {
                            callback(error);
                        }
                    }
                } else if (catchBody) {
                    try {
                        catchBody(error, callback);
                    } catch (error) {
                        callback(error);
                    }
                } else {
                    try {
                        finallyBody(function(finallyError) {
                            callback(finallyError || error, finallyError ? undefined : result);
                        });
                    } catch (error) {
                        callback(error);
                    }
                }
            } else {
                if (finallyBody) {
                    try {
                        finallyBody(function(finallyError) {
                            callback(finallyError, finallyError ? undefined : result);
                        });
                    } catch (error) {
                        callback(error);
                    }
                } else {
                    callback(undefined, result);
                }
            }
        });
    } catch (error) {
        if (finallyBody && catchBody) {
            try {
                catchBody(error, function(error, result) {
                    try {
                        finallyBody(function(finallyError) {
                            callback(finallyError || error, finallyError ? undefined : result);
                        });
                    } catch (error) {
                        callback(error);
                    }
                });
            } catch (error) {
                try {
                    finallyBody(function(finallyError) {
                        callback(finallyError || error);
                    });
                } catch (error) {
                    callback(error);
                }
            }
        } else if (catchBody) {
            try {
                catchBody(error, callback);
            } catch (error) {
                callback(error);
            }
        } else {
            try {
                finallyBody(function(finallyError) {
                    callback(finallyError || error);
                });
            } catch (error) {
                callback(error);
            }
        }
    }
};

record = void 0;

gen1_asyncTry(function(continuation) {
    var gen2_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    connectToTheDatabase(function(gen3_error, gen4_asyncResult) {
        var database;
        if (gen3_error) {
            continuation(gen3_error);
        } else {
            try {
                database = gen4_asyncResult;
                database.query(function(gen5_error, gen6_asyncResult) {
                    if (gen5_error) {
                        continuation(gen5_error);
                    } else {
                        try {
                            continuation(void 0, record = gen6_asyncResult);
                        } catch (gen7_exception) {
                            continuation(gen7_exception);
                        }
                    }
                });
            } catch (gen8_exception) {
                continuation(gen8_exception);
            }
        }
    });
}, function(error, continuation) {
    var gen9_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    error = gen9_arguments[0];
    exitTheProgramBecauseOf(error, continuation);
}, function(continuation) {
    var gen10_arguments = Array.prototype.slice.call(arguments, 0, arguments.length - 1);
    continuation = arguments[arguments.length - 1];
    if (!(continuation instanceof Function)) {
        throw new Error("asynchronous function called synchronously");
    }
    database.close(continuation);
}, function(gen11_error, gen12_asyncResult) {
    if (gen11_error) {
        continuation(gen11_error);
    } else {
        try {
            gen12_asyncResult;
            continuation(void 0, console.log("RECORD FOUND: " + record));
        } catch (gen13_exception) {
            continuation(gen13_exception);
        }
    }
});