View gist:4221609
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 urls = ['google.com', 'youtube.com', 'cracked.com']; | |
var fs = require('fs'), | |
http = require('http'), | |
url = require('url'), | |
path = require('path'); | |
var count = 0; | |
urls.map(url.parse).forEach(function (url) { | |
http.get(url, function (res) { |
View closure.js
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 x = 5; | |
function myClosure (y) { | |
return x + 1; | |
}; | |
console.log(myClosure(10)); // 6 |
View shadowing.js
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 x = 5; | |
function myClosure (x) { | |
return x + 1; | |
}; | |
console.log(myClosure(10)); // 11 |
View broken_closure.rb
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
x = 5 | |
def my_closure y | |
x + 1 | |
end | |
puts my_closure 10 # NameError: undefined local variable or method `x' for main:Object |
View closure.rb
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
x = 5 | |
my_closure = -> x do | |
x + 1 | |
end | |
puts my_closure.call 10 # 6 |
View broken_closure.rs
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
fn main () { | |
let x: int = 5; | |
fn my_closure (y: int) { | |
x + 1; | |
} | |
io::println(my_closure(10)); // error: attempted dynamic environment-capture, unresolved name: x | |
} |
View verbose_closure.rs
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
fn main () { | |
let x: int = 5; | |
let my_closure = |_: int| -> int { | |
x + 1 | |
}; | |
io::println(fmt!("%d",my_closure(10))); // 6 | |
} |
View succint_closure.rs
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
fn main () { | |
//let x: int = 5; | |
let x = 5; | |
//let my_closure = |_: int| -> int { | |
let my_closure = |_| { | |
x + 1 | |
}; | |
io::println(fmt!("%?",my_closure(10))); // 6 |
View function_pointers.c
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
// compiled with: | |
// clang -Wall -Wextra function_pointers.c -o function_pointers | |
#include "stdio.h" | |
void usual_syntax (void (*fn) (int x)) { | |
puts("usual syntax start"); | |
fn(1); | |
puts("usual syntax end"); | |
} |
View function_pointer
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
hello world | |
usual syntax start | |
hello 1 | |
usual syntax end | |
other syntax start | |
hello 2 | |
other syntax end |
OlderNewer