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) { |
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 |
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 |
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 |
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 |
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 | |
} |
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 | |
} |
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 |
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"); | |
} |
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