1
isaced 2014-01-21 09:13:21 +08:00
这两种不一样的吧?
|
2
wheatcuican 2014-01-21 09:13:45 +08:00
哈哈~
@kstsca |
3
FrankFang128 2014-01-21 09:18:25 +08:00 via Android
II
|
4
miniwade514 2014-01-21 09:22:55 +08:00
这是啥,异步/同步?单线程/多线程?
|
5
Golevka 2014-01-21 09:26:50 +08:00
CPS
|
6
ipconfiger 2014-01-21 09:27:47 +08:00 2
程序员应该是分为10类,一类是懂二进制的,一类是不懂二进制的
|
7
housne 2014-01-21 09:35:10 +08:00
nodejs 写多了就变成了 Type II.
|
8
leofml 2014-01-21 09:51:23 +08:00
@miniwade514 函数式 过程式
|
9
arcas 2014-01-21 10:18:04 +08:00
你真无聊!
|
10
dorentus 2014-01-21 10:19:40 +08:00 via iPhone
这两组代码做的根本就不是同一件事…
|
11
miniwade514 2014-01-21 10:26:56 +08:00
|
12
subpo 2014-01-21 10:31:57 +08:00
2
|
13
helone 2014-01-21 10:53:40 +08:00
人也应该分两种,一种喜欢把人归类,另一种不喜欢把人归类。
|
14
lm902 2014-01-21 11:08:40 +08:00
插入?好吧我想多了
|
15
wity_lv 2014-01-21 11:48:06 +08:00
Type II的威力:
(define (sum term a next b) (define (iter a result) (if (> a b) result (iter (next a) (+ (term a) result)))) (iter a 0)) (sum (lambda (x) x) 1 (lambda (i) (+ 1 i)) 10) |
21
mikawudi 2014-01-22 02:18:29 +08:00
Func<Func<int, int>, int, Func<int, int>, int, int> sum = (term, a, next, b) =>
{ Func<int, int, int> iter = null; iter = (a1, result) => { if (a1 > b) return result; else return iter(next(a1), term(a1) + result); }; return iter(a, 0); }; int ss = sum((x) => { return x; }, 1, (i) => { return i + 1; }, 10); C#版本.....简单来说是做累加,不过写的更泛用了....步长和每一次对累加值可以进行自定义....差不多这个意思?....写完才发现lambda表达式貌似不能递归自己....还要显示声明下再用引用来递归...好难受 |
23
wity_lv 2014-01-22 09:59:39 +08:00
@loading
@housne @yuankui @mikawudi 给一个javascript版本, 用高阶函数做抽象. function sum (term, a, next, b) { function iter (a, result) { if (a > b) { return result; } var ret = term(a) + result; return iter(next(a), ret); } return iter(a, 0); } var all = sum(function(x) { return x; }, 1, function(x) { return x + 1; }, 100); console.log(all); |
24
wity_lv 2014-01-22 10:01:34 +08:00
|
26
nybux 2014-01-22 13:51:21 +08:00
#include <iostream>
#include <functional> template<typename F1, typename F2, typename T> int sum(F1 term, T a, F2 next, T b) { std::function<int(T,T)> iter = [&](T a, T result){ return (a > b) ? result : iter(next(a), term(a) + result); }; return iter(a, 0); } int main() { int all = sum([](int x) { return x; }, 1, [](int x) { return x + 1;}, 100); std::cout << all << std::endl; } |
27
halfblood 2014-01-23 12:50:16 +08:00
过程式和函数式而已!
整天讨论这些有毛用啊…… |