• <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
            久久天天躁狠狠躁夜夜躁2O2O| 精品蜜臀久久久久99网站| 亚洲精品无码久久久久去q| 国产免费久久久久久无码| 久久亚洲熟女cc98cm| 久久久精品久久久久久| 国产精品福利一区二区久久| 久久久久青草线蕉综合超碰 | 狼狼综合久久久久综合网| 久久精品亚洲乱码伦伦中文| 国产精品久久久久久| 久久婷婷激情综合色综合俺也去| 偷偷做久久久久网站| 日日狠狠久久偷偷色综合96蜜桃 | 精品久久久久久国产| 欧美精品丝袜久久久中文字幕 | 久久久久人妻一区精品| 99久久99久久精品国产| 久久免费视频观看| 久久精品草草草| 国产美女久久精品香蕉69| 久久精品国产精品亚洲毛片| 久久午夜羞羞影院免费观看| 久久精品国产99国产精品亚洲| 少妇久久久久久被弄到高潮 | av无码久久久久不卡免费网站 | 亚洲精品无码专区久久久| 久久天天躁狠狠躁夜夜躁2O2O| 日日躁夜夜躁狠狠久久AV| 久久精品www人人爽人人| 久久99国产亚洲高清观看首页 | 蜜臀久久99精品久久久久久小说 | 久久亚洲欧美日本精品| 香蕉久久一区二区不卡无毒影院 | 色偷偷888欧美精品久久久| 久久99精品久久久久久动态图| 久久精品亚洲精品国产色婷| 久久精品国产亚洲av影院| 一本大道久久a久久精品综合| 久久国产精品视频| 色播久久人人爽人人爽人人片aV|