我倒是觉得程序员分这样2类 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
kurtis
V2EX    程序员

我倒是觉得程序员分这样2类

  •  
  •   kurtis 2014-01-21 09:11:27 +08:00 5347 次点击
    这是一个创建于 4290 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Type I.
    proc1();
    proc2();

    Type II.
    proc1(proc2);
    27 条回复    1970-01-01 08:00:00 +08:00
    isaced
        1
    isaced  
       2014-01-21 09:13:21 +08:00
    这两种不一样的吧?
    wheatcuican
        2
    wheatcuican  
       2014-01-21 09:13:45 +08:00
    哈哈~
    @kstsca
    FrankFang128
        3
    FrankFang128  
       2014-01-21 09:18:25 +08:00 via Android
    II
    miniwade514
        4
    miniwade514  
       2014-01-21 09:22:55 +08:00
    这是啥,异步/同步?单线程/多线程?
    Golevka
        5
    Golevka  
       2014-01-21 09:26:50 +08:00
    CPS
    ipconfiger
        6
    ipconfiger  
       2014-01-21 09:27:47 +08:00   2
    程序员应该是分为10类,一类是懂二进制的,一类是不懂二进制的
    housne
        7
    housne  
       2014-01-21 09:35:10 +08:00
    nodejs 写多了就变成了 Type II.
    leofml
        8
    leofml  
       2014-01-21 09:51:23 +08:00
    @miniwade514 函数式 过程式
    arcas
        9
    arcas  
       2014-01-21 10:18:04 +08:00
    你真无聊!
    dorentus
        10
    dorentus  
       2014-01-21 10:19:40 +08:00 via iPhone
    这两组代码做的根本就不是同一件事…
    miniwade514
        11
    miniwade514  
       2014-01-21 10:26:56 +08:00
    @housne ,在 SegmentFault 上见过你,node 达人,哈哈。

    @leofml ,谢谢 :) 忘了第一种叫过程式了…… JS 里的 callback 就是函数式的一种实践吧?
    subpo
        12
    subpo  
    PRO
       2014-01-21 10:31:57 +08:00
    2
    helone
        13
    helone  
       2014-01-21 10:53:40 +08:00
    人也应该分两种,一种喜欢把人归类,另一种不喜欢把人归类。
    lm902
        14
    lm902  
       2014-01-21 11:08:40 +08:00
    插入?好吧我想多了
    wity_lv
        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)
    loading
        16
    loading  
       2014-01-21 11:55:42 +08:00 via iPhone
    @wity_lv WTF!
    yuankui
        17
    yuankui  
       2014-01-21 12:16:44 +08:00
    @wity_lv WTF!
    housne
        18
    housne  
       2014-01-21 13:14:28 +08:00
    @wity_lv 传说中的 lisp 么 。。。 完全看不懂啊 。。。
    yuankui
        19
    yuankui  
       2014-01-21 14:29:44 +08:00
    @wity_lv WTF!
    yuankui
        20
    yuankui  
       2014-01-21 14:30:08 +08:00
    @wity_lv WTF。。
    mikawudi
        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表达式貌似不能递归自己....还要显示声明下再用引用来递归...好难受
    mikawudi
        22
    mikawudi  
       2014-01-22 02:20:15 +08:00
    @dorentus CPS变换了...其实做的是一回事
    wity_lv
        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);
    wity_lv
        24
    wity_lv  
       2014-01-22 10:01:34 +08:00
    mikawudi
        25
    mikawudi  
       2014-01-22 13:08:42 +08:00 via Android
    @wity_lv 看了下哥们的帖子。。。。果然看到了sicp
    nybux
        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;
    }
    halfblood
        27
    halfblood  
       2014-01-23 12:50:16 +08:00
    过程式和函数式而已!
    整天讨论这些有毛用啊……
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1655 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 120ms UTC 16:24 PVG 00:24 LAX 09:24 JFK 12:24
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86