-
-
Save creationix/1b47cba9f3a066147966 to your computer and use it in GitHub Desktop.
Feeling out continuable syntax in coffeescript, javascript, and lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs') | |
open = (path, flags, mode) -> (callback) -> | |
fs.open(path, flags, mode or 438, callback) | |
close = (fd) -> (callback) -> | |
fs.close(fd, callback) | |
open("home.txt", "r") (err, fd) -> | |
throw err if err | |
console.log("Opened") | |
close(fd) (err) -> | |
throw err if err | |
console.log("Closed") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
function open(path, flags, mode) { | |
return function (callback) { | |
fs.open(path, flags, mode || 0666, callback); | |
}; | |
} | |
function close(fd) { | |
return function (callback) { | |
fs.close(fd, callback); | |
}; | |
} | |
open("home.txt", "r")(function(err, fd) { | |
if (err) throw err; | |
console.log("Opened"); | |
close(fd)(function(err) { | |
if (err) throw err; | |
console.log("Closed"); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local fs = require "fs" | |
local function open(path, flags, mode) | |
return function (callback) | |
fs.open(path, flags, mode or "0666", callback) | |
end | |
end | |
local function close(fd) | |
return function (callback) | |
fs.close(fd, callback) | |
end | |
end | |
open("home.txt", "r")(function (err, fd) | |
if err then error(err) end | |
print "Opened" | |
close(fd)(function (err) | |
if err then error(err) end | |
print "Closed" | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LiveScript: