zoukankan      html  css  js  c++  java
  • Erlang function guards NOTE

      Note: I've compared , and ; in guards to the operators andalso and orelse. They're not exactly the same, though. The former pair will catch exceptions as they happen while the latter won't. What this means is that if there is an error thrown in the first part of the guard X >= N; N >= 0, the second part can still be evaluated and the guard might succeed; if an error was thrown in the first part of X >= N orelse N >= 0, the second part will also be skipped and the whole guard will fail.

      However (there is always a 'however'), only andalso and orelse can be nested inside guards. This means (A orelse B) andalso C is a valid guard, while (A; B), C is not. Given their different use, the best strategy is often to mix them as necessary.

      这里的意思是用X >= N; N >= 0的时候不能嵌套使用(像这样(A;B), C这样是不行的),而且这种写法不是惰性求值,X>=N求值为真时会继续对N>=0进行求值,但是这种写法会捕捉Exception。相反用X >= N orelse N >= 0的时候是能嵌套使用(像(A orelse B) andalso C这样是可行的),而且这种写法是惰性求值,只要第一个表达式为真后面的表达式将不再求值。

      上面的英文部分摘录自Learn You Some Erlang for Great Good!

  • 相关阅读:
    Intern Day42
    Intern Day42
    Intern Day42
    Intern Day40
    腾讯PC客户端二面
    面试
    面试
    面试
    计算机网络
    计算机网络
  • 原文地址:https://www.cnblogs.com/kiven-code/p/3761702.html
Copyright © 2011-2022 走看看