Go: 6-1 函数式编程

特点
//golang 
func adder() func(int) int {
	sum := 0 //自由变量
	return func(v int) int {
		sum += v
		return sum
	}
}

//python
def adder();
    sum = 0
    def f(value):
        nonlocal sum
        sum += value
        return sum
    return f    
    
    
// c++ 14中的闭包    
auto adder(){
    auto sum = 0;
    return [=] (int value)mutable{
        sum += value;
        return sum;
    };
}

//java中的闭包
Function<Integer,Integer>adder(){
    final Holder<Integer> sum = new Holder<>(0);
    return (Integer value) -> {
        sum.value += value;
        return sum.value;
    }
}