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!

Erlang function guards NOTE的更多相关文章

  1. [Erlang 0120] Know a little Core Erlang

      Erlang开发者或多或少都用过或者听说过Core erlang,它是什么样的呢?新建一个测试模块a.erl,如下操作会生成core erlang代码而非a.beam:   Eshell V6.0 ...

  2. [Erlang 0119] Erlang OTP 源码阅读指引

      上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的?   "代码去哪里找?",关于Erla ...

  3. Named function expressions demystified

    Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...

  4. [JavaScript-Function] Function Invocation/Call(函数调用) 以及call() and apply() 方法

    介绍:JS函数中的代码会被函数被invoke(调用)时执行. 函数被定义时代码不执行, 函数调用时函数内的代码会被执行. 常用的term是 call a function 而不是 invoke a f ...

  5. Centos7 Erlang Solutions 安装

    https://www.erlang-solutions.com/resources/download.html Installation using repository 1. Adding rep ...

  6. Erlang模块ets翻译

    概要: 内置的存储 描述: 这个模块是Erlang内置存储BIFs的接口.这些提供了在Erlang运行时系统中存储大量数据的能力,并且能够对数据进行持续的访问时间.(在ordered_set的情况下, ...

  7. 安装thrift全过程

    为了研究基于thrift的RPC框架,其实,是想自己基于thrift写一个微服务的platform.首先就是安装Thrift,便于IDL架构生成java的接口文件.多的不说了,开始install的过程 ...

  8. C++ Core Guidelines

    C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...

  9. 初探React,将我们的View标签化

    前言 我之前喜欢玩一款游戏:全民飞机大战,而且有点痴迷其中,如果你想站在游戏的第一阶梯,便需要不断的练技术练装备,但是腾讯的游戏一般而言是有点恶心的,他会不断的出新飞机.新装备.新宠物,所以,很多时候 ...

随机推荐

  1. hdu 1695 容斥原理或莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  2. poj 3532 Resistance

    ---恢复内容开始--- Resistance Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 1289   Accepte ...

  3. Linq技巧3——何时及怎么使用预先加载

    通常情况在你的应用程序中,一旦你要查询完数据的的时候,你知道使用实体来做什么. 假如你打印一份订单给顾客,你知道不包括组成订单的Items和Products信息,打印的信息是不完整的,所以查询时也需要 ...

  4. 32深入理解C指针之---字符串操作

    一.字符串操作主要包括字符串复制.字符串比较和字符串拼接 1.定义:字符串复制strcpy,字符串比较strcmp.字符串拼接strcat 2.特征: 1).必须包含头文件string.h 2).具体 ...

  5. mysql 初始化脚本

    脚本须知: 1. 确认mysql的数据目录,二进制日志目录,中继日志的目录,安装目录的位置 2. 初始化会对前三个目录执行清空操作,不过清空前该脚本对其进行了压缩打包统一存放在/tmp目录下 3. 脚 ...

  6. Scrapy学习-17-暂停和重启

    Scrapy爬虫暂停和重启 在当前项目下新建一个用于存储中间过程变量的目录 注意不同的spider不能共用一个目录 同一个spider每次运行时也必须使用新的目录 mkdir <spider_p ...

  7. AC日记——[福利]可持久化线段树 cogs 2554

    2554. [福利]可持久化线段树 ★★☆   输入文件:longterm_segtree.in   输出文件:longterm_segtree.out   简单对比时间限制:3 s   内存限制:2 ...

  8. es6 export、import

    一.输出变量 1.export var a = 0; 2.var a = 0'; export {a}; 3.var a =0 ; export {a as rename}; //使用as重命名的对外 ...

  9. Debian9安装MariaDB

    一:导入密钥并添加了存储库 sudo apt-get install software-properties-common dirmngr sudo apt-key adv --recv-keys - ...

  10. 洛谷——P1238 走迷宫

    P1238 走迷宫 题目描述 有一个m*n格的迷宫(表示有m行.n列),其中有可走的也有不可走的,如果用1表示可以走,0表示不可以走,文件读入这m*n个数据和起始点.结束点(起始点和结束点都是用两个数 ...