1 2 3 4 5 6 7 8 9 | function addx(x) { return function(y) {return x+y;}; } add8 = addx(8); add9 = addx(9); alert(add8(100)); alert(add9(100)); |
1 2 3 | sum = 0 10.times{|n| sum += n} print sum |
1 2 3 4 5 6 7 8 9 | def addx(x): def adder (y): return x + y return adder add8 = addx(8) add9 = addx(9) print add8(100) print add9(100) |
1 2 3 4 5 6 7 8 | def addx(x): return lambda y: x + y add8 = addx(8) add9 = addx(9) print add8(100) print add9(100) |
1 2 3 4 5 6 7 8 9 10 | sub addx { my $x = shift; return sub { shift() + $x }; } $add8 = addx(8); $add9 = addx(9); print $add8->(100); print $add9->(100); |
1 2 3 4 5 6 7 8 | (define (addx x) (lambda (y) (+ y x))) (define add8 (addx 8)) (define add9 (addx 9)) (add8 100) (add9 100) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |