JS with defer(s) built of top of XJS.
function init() {
let db = openDb()
defer closeDb(db)
let file = openFile('myfile.txt')
defer {
console.log('closing file')
closeFile(file)
}
// db and file operations ...
}
function init() {
let __defers_2a78ec64__ = [];
try {
{
let db = openDb();
__defers_2a78ec64__.unshift(() => {
closeDb(db);
});
let file = openFile("myfile.txt");
__defers_2a78ec64__.unshift(() => {
{
console.log("closing file");
closeFile(file);
}
});
}
} finally {
for (let defer of __defers_2a78ec64__) {
try {
defer();
} catch (e) {
console.error(e);
}
}
}
}
For language ergonomics. Writing a try/finally block for every resource we want to release is cumbersome and hinders the natural reading of the code.
[!NOTE] The latest versions of JS already have the
usingdeclaration, but it is still cumbersome and only available recent versions.
You'll need Go. Once installed, simply do this:
git clone <this repo>
go install ./cmd/djs
Examples of use:
djs <file.djs> # compile DJS to JS
djs <file.djs> | node # compile and run
djs -format <file.djs> # format DJS
djs -check <file.djs> # check for errors
225 commits
Hacker News (1)
Go
97.3%
Dogescript
2.7%
JS with defer(s) built of top of XJS.
function init() {
let db = openDb()
defer closeDb(db)
let file = openFile('myfile.txt')
defer {
console.log('closing file')
closeFile(file)
}
// db and file operations ...
}
function init() {
let __defers_2a78ec64__ = [];
try {
{
let db = openDb();
__defers_2a78ec64__.unshift(() => {
closeDb(db);
});
let file = openFile("myfile.txt");
__defers_2a78ec64__.unshift(() => {
{
console.log("closing file");
closeFile(file);
}
});
}
} finally {
for (let defer of __defers_2a78ec64__) {
try {
defer();
} catch (e) {
console.error(e);
}
}
}
}
For language ergonomics. Writing a try/finally block for every resource we want to release is cumbersome and hinders the natural reading of the code.
[!NOTE] The latest versions of JS already have the
usingdeclaration, but it is still cumbersome and only available recent versions.
You'll need Go. Once installed, simply do this:
git clone <this repo>
go install ./cmd/djs
Examples of use:
djs <file.djs> # compile DJS to JS
djs <file.djs> | node # compile and run
djs -format <file.djs> # format DJS
djs -check <file.djs> # check for errors
Hacker News (1)
225 commits
Go
97.3%
Dogescript
2.7%