• <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
            <2017年1月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234


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

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 215415
            • 排名 - 118

            最新評論

            閱讀排行榜

            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 思月行云 閱讀(183) 評論(0)  編輯 收藏 引用 所屬分類: Erlang
            久久福利资源国产精品999| 国产精品成人99久久久久| 青青青青久久精品国产| 亚洲色大成网站www久久九| 久久无码精品一区二区三区| 91久久精品国产成人久久| 狠狠色丁香婷婷综合久久来| 久久久久亚洲av无码专区喷水| 伊人久久精品无码av一区| 欧美牲交A欧牲交aⅴ久久 | 婷婷久久香蕉五月综合加勒比| 久久精品一区二区三区中文字幕| 日韩一区二区久久久久久| 国产精品99久久精品爆乳| 久久精品国产精品亚洲艾草网美妙| 精品免费久久久久国产一区| 久久91精品综合国产首页| 亚洲国产成人久久综合野外| 久久久久av无码免费网| 亚洲AV无码久久寂寞少妇| 国产成人精品久久一区二区三区| 国产精品一区二区久久| 久久综合给合综合久久| 久久久久久久精品成人热色戒| 亚洲精品无码久久久久久| 久久精品国产精品亚洲毛片| 中文字幕成人精品久久不卡 | 久久久久国产一级毛片高清板 | 久久五月精品中文字幕| 久久人妻无码中文字幕| 久久综合欧美成人| 老男人久久青草av高清| 久久91综合国产91久久精品| 思思久久99热免费精品6| 精品综合久久久久久888蜜芽| 26uuu久久五月天| 无码伊人66久久大杳蕉网站谷歌 | 亚洲精品高清国产一久久| 亚洲AV伊人久久青青草原| 精品免费久久久久久久| 久久久久国产精品麻豆AR影院|