I first learned about first class functions in Javascript, and I really loved the possibility of doing something like this :
function x(a,fun) {
for(var i = 0;i<a.length;i++) {
fun(a[i]);
}
}
x([1,2,3],function(x) {
alert(x);
});
The possibility of passing whatever variable and using it as a function blew my mind 3 years ago. These days I use Javascript very little, I’m doing most of my coding in Java/Python/Ruby. We all know the deal about Java and first class functions ( sucks ). Ruby has lambdas and procs, which, in order to be executed, you must call the call method… so, there’s an extra step you have to make. The closest to Javascript syntax is Python, where you have a function like this :
def x(a,fun):
for elem in a:
fun(a)
def show(elem):
print elem
# and you call it like this:
x([1,2,3],show)
Can your language do this? 