I'm asking if first class functions also can be closures. Does it use lexical binding?
i think i answered that question already, which is yes, but technically no. here is a rough Javascript version of the original example:
makeObj[] := Module[{obj, i = 0},
obj["inc"] := ++i;
obj["dec"] := --i;
obj[] := i;
obj];
makeObj = function() {
var i = 0;
var obj = function(in) {
switch(in) {
case "inc" : return ++i;
case "dec" : return --i;
case undefined: return i;
};
};
return obj;
};
you can do, for example:
where the result will be either 5 or 6. in more explicit form: example of an "anonymous" function: square of all numbers from 1 to 100: simpler form: all pairwise products of the first seven prime numbers (among themselves): etc.