erlang符号に関する基本文法

4533 ワード

http://blog.csdn.net/anghlq/article/details/6803332
ErrLang文法の約束:
  • 頭文字の先頭の名前(例えば、Address)は、パラメータ、局所変数などを含む変数を表します.
  • 小文字で始まる単語(例えばok)は、常量を表し、アトム(原子の意味)といい、定数名、関数名、モジュール名などを含みます.
  • Erringの注釈は%で始まる.ErrLangはアンダースコアで「_」を任意変数と表し、JavaのSwitch文法のdefaultに似ています.
  • パラメータでは使用されていない変数は、_などの下棒と頭文字で大文字になります.Sample
  • 比較記号
     
    op
    Description
    ==
    equal to
    //
    not equal to
    =<
    less than or equal to
    <>
    less than
    >=
    greater than or equal to
    >
    greater than
    ==
    exactly equal to
    ==
    exactly not equal to
     
    1> 1==1.0.
    
    true
    
    2> 1=:=1.0. false    
    op
    Description
    アーティファクトタイプ

    unary+
    number
    を選択します.
    unary-
    number

     
    number
    を選択します.
     
    number

     
    number
    を選択します.
    float point division
    number
    bnot
    unary bitwise not
    インテグ
    div
    インテグディヴィジョン
    インテグ
    レム
    integer remander of X/Y
    インテグ
    バンド
    bitwise and
    インテグ
    bor
    bitwise or
    インテグ
    bxor
    arthmetic bitwise xor
    インテグ
    bsl
    arthmetic bitshift left
    インテグ
    bsr
    bit shift right
    インテグ
    7> 2#10 band 2#01.
    
    0
    
    8> 2#10 bor 2#01. 3
     
     
      

     

    Boolean表达式

     

    op Description
    not unary logical not
    and logical and
    or logical or
    xor logical xor

     

    短路表达式

    Expr1 orelse Expr2
    Expr1 andalso Expr2

     

    case A >= -1.0 andalso math:sqrt(A+1) > B of
    リスト式
     
    +++--
     
    1> [1,2,3]++[4,5].
    
    [1,2,3,4,5]
    
    2> [1,2,3,2,1,2]--[2,1,2]. [3,1,2]
     
    バイナリ表現
     
    <<>>
    
    <<E1,...,En>>
    Ei=Value|     Value:Size|     Value/Type Specifier List|     Value:Size/Type Specifier List
     
     
    Type Specifer List 
  • Type= インテグ | float | binary | bytes |ビットストリーム | ビッツ | utf 8 | utf 16 | utf 32
  • Signedness= signed | unsigned

  • Edianness= big | リトル | native
    ユニット= unit:IntegerLiteral
  • 11> <<G,H/bitstring>> = <<1,17,42:12>>.
    
    <<1,17,1,10:4>>
    
    12> H. <<17,1,10:4>> 13> <<1024/utf8>>. <<208,128>>
    スペースB=<<1>>を追加すると、比較記号=<衝突、
    <「-\r」、Data/binary>、
     
    strchr(Bin,C,I)->    case Bin of        <<_X:I/binary>->            0;        <<_X:I/binary,C,_Reset/binary>->            I+1;        _ ->            strchr(Bin,C,I+1)    end.
    パーシ_bootlean(Value)->    case Value of        true->true;        false->false;        <<「true」>->true;        <->false;        <<「1」>->true;        <<「0」>->false;        1->>true;        0->false    end.
    <=Bin.<=Bin.case Packet of    <->        {body,PayLoad}    _ ->        {error,invaliduplacket}end.    case Info of            <<「get」、Str 1/bitstring>->            オ:format(「case 0:~s~n」、「binaryキャット(Str 1)」);        <<1:1、Str 1/bitstring>->            オ:format(「case 1:~s~n」、[Str 1])    end.