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!

转载于:https://www.cnblogs.com/kiven-code/p/3761702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值