• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Fork me on GitHub
            隨筆 - 215  文章 - 13  trackbacks - 0
            <2016年11月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910


            專注即時(shí)通訊及網(wǎng)游服務(wù)端編程
            ------------------------------------
            Openresty 官方模塊
            Openresty 標(biāo)準(zhǔn)模塊(Opm)
            Openresty 三方模塊
            ------------------------------------
            本博收藏大部分文章為轉(zhuǎn)載,并在文章開頭給出了原文出處,如有再轉(zhuǎn),敬請(qǐng)保留相關(guān)信息,這是大家對(duì)原創(chuàng)作者勞動(dòng)成果的自覺尊重!!如為您帶來不便,請(qǐng)于本博下留言,謝謝配合。

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊(cè)

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 217667
            • 排名 - 118

            最新評(píng)論

            閱讀排行榜

            http://www.jb51.net/article/59401.htm
            一、賦值時(shí)匹配

            原子匹配

            復(fù)制代碼 代碼如下:

            atom    = atom                        % atom
            another = another                     % another
            atom    = another                     % exception error

            變量匹配
            復(fù)制代碼 代碼如下:

            Var = 2.                              % 2
            Var = 3 - 1.                          % 2
            Var = 1.                              % exception error

            元組匹配
            復(fù)制代碼 代碼如下:

            Attr = {name, sloger}.                % {name, sloger}
            {name, Name} = Attr.                  % {name, sloger}
            Name.                                 % sloger

            列表匹配
            復(fù)制代碼 代碼如下:

            Langs = [perl, python, ruby, erlang].
            [Head | Tail] = Langs.
            Head.                                 % perl
            Tail.                                 % [python, ruby, erlang]

            參數(shù)匹配
            復(fù)制代碼 代碼如下:

            sum([]) -> 0;
            sum([H|T]) -> H + sum(T).

             

            sum([1, 2, 3]).                       % 6


            記錄匹配
            復(fù)制代碼 代碼如下:

            %% record(post, {title, slug, body, author}).

             

            Post = #post{title = "Pattern Match in Erlang",
                         slug = "pattern-match-in-erlang",
                         body = "Bla bla bla...",
                         author = sloger}.

            #post{title = Title, slug = Slug} = Post.

            Title.                                % "Erlang 中的模式匹配總結(jié)"
            Slug.                                 % "summary-of-pattern-match-in-erlang"


            比特匹配
            復(fù)制代碼 代碼如下:

            Red = 5.
            Green = 23.
            Blue = 200.

             

            Color = <<Red:5, Green:6, Blue:5>>.

            <<R1:5, G1:6, B1:5>> = Color.

            R1.                                   % 5
            G1.                                   % 23
            B1.                                   % 200


            二、流程控制中的匹配

             

            if

            復(fù)制代碼 代碼如下:

             

            if
                Pattern1 [when Guard1] -> Expression1;
                Pattern2 [when Guard2] -> Expression2;
                %% and so on ...
                _                      -> Expression3           % 匹配所有其它結(jié)果
            end.

             


            case

             

             

            復(fù)制代碼 代碼如下:

             

            case Expression of
                Pattern1 [when Guard1] -> Expression1;
                Pattern2 [when Guard2] -> Expression2;
                %% and so on ...
                _                      -> Expression3
            end.

             


            try catch

             

             

            復(fù)制代碼 代碼如下:

             

            try FunctionOrExpressions of
                Pattern1 [when Guard1] -> Expression1;
                Pattern2 [when Guard2] -> Expression2
                %% and so on ...
            catch
                ExType:ExPattern1 [when ExGuard1] ->
                    ExExpression1;
                ExType:ExPattern2 [when ExGuard2] ->
                    ExExpression2;
                %% and so on ...
                _:_ -> DefaultExExpression               % _:_ 匹配所有異常
            after
                AfterExpressions
            end

             

            消息傳遞匹配

            復(fù)制代碼 代碼如下:

            loop() ->
                receive
                    {From, {rectangle, Width, Height}} ->
                        From ! {self(), Width * Height},
                        loop();
                    {From, {circle, R}} ->
                        From ! {self(), 3.14 * R * R},
                        loop();
                    {From, _Other} ->
                        From ! {self(), {error, unknown_shape}}
                        loop()
                end.
            Pid = spawn(fun loop/0).
            Pid ! {self(), {rectangle, 10, 5}}.         % {Pid, 50}
            Pid ! {self(), {circle, 4}}.                % {Pid, 50.24}
            Pid ! {self(), {square, 10}}.               % {Pid, {error, unknown_shape}}

             

            posted on 2017-01-11 19:06 思月行云 閱讀(190) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Erlang
            久久精品国产色蜜蜜麻豆| 国产99久久久国产精免费| 91久久精品视频| 99久久夜色精品国产网站| 婷婷久久综合九色综合绿巨人| 亚洲中文字幕伊人久久无码| 国产精品一区二区久久精品涩爱| 亚洲精品乱码久久久久久蜜桃图片 | 午夜精品久久久久久影视riav| 久久久久久久久久久精品尤物 | 色综合久久久久无码专区| 久久精品成人免费网站| 久久久国产打桩机| 久久99精品国产| 东方aⅴ免费观看久久av| 久久国产成人午夜AV影院| 精品伊人久久大线蕉色首页| 91精品国产综合久久婷婷| 日本精品久久久久影院日本 | 欧美精品一本久久男人的天堂| 久久亚洲中文字幕精品一区四| 久久亚洲精品中文字幕三区| 色8久久人人97超碰香蕉987| 色综合久久天天综线观看| 99久久777色| 国产精品对白刺激久久久| 一本久久知道综合久久| 国内精品伊人久久久久妇| 色诱久久av| 午夜精品久久久久久久无码| 99久久国产免费福利| 国产精品久久免费| 9久久9久久精品| 青草影院天堂男人久久| 久久电影网2021| 亚洲国产精品久久久久婷婷老年| 久久婷婷国产综合精品| 色8久久人人97超碰香蕉987| 亚洲午夜久久久久久久久久| 亚洲精品国产美女久久久| 久久婷婷激情综合色综合俺也去|