Erlang style - case vs function pattern matching

后端 未结 6 1613
眼角桃花
眼角桃花 2020-12-31 02:39

I\'ve got to the stage where I\'ve written quite a bit of Erlang code now, and I can see some style (bad or good) creeping into the way I\'ve been writing it. This particula

6条回答
  •  攒了一身酷
    2020-12-31 02:50

    (Put as an answer to get the formatting of the code...!)

    One thing I did find when I was making some changes is that this approach can alter default short circuiting. E.g.

    case A > 10 of 
          true -> 
                 case B > 10 of 
                      true -> dummy1; 
                      false -> dummy2 
                 end; 
          false -> dummy3 
    end 
    

    would have to always execute B > 10 if you called it like

    doTest(A > 10, B > 10) 
    

    when

    doTest(true, true) -> dummy1; 
    doTest(true, false) -> dummy2; 
    doTest(false, _) -> dummy3. 
    

    which sometimes isn't what you want!

提交回复
热议问题