Can I make my own Guards in Erlang?

前端 未结 2 457
日久生厌
日久生厌 2020-12-20 14:37

I came accross this code on the web:

is_char(Ch) ->         
    if Ch < 0 -> false;  
       Ch > 255 -> false;
       true -> true      
         


        
2条回答
  •  既然无缘
    2020-12-20 15:32

    Another reason for not allowing user defined functions in guards is that errors are handled differently in guards than in "normal" functions. In a guard an error does not generate an exception, it only causes the guard itself to fail.

    Guards are not really expressions but tests.

提交回复
热议问题