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!
Erlang function guards NOTE的更多相关文章
- [Erlang 0120] Know a little Core Erlang
Erlang开发者或多或少都用过或者听说过Core erlang,它是什么样的呢?新建一个测试模块a.erl,如下操作会生成core erlang代码而非a.beam: Eshell V6.0 ...
- [Erlang 0119] Erlang OTP 源码阅读指引
上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的? "代码去哪里找?",关于Erla ...
- Named function expressions demystified
Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...
- [JavaScript-Function] Function Invocation/Call(函数调用) 以及call() and apply() 方法
介绍:JS函数中的代码会被函数被invoke(调用)时执行. 函数被定义时代码不执行, 函数调用时函数内的代码会被执行. 常用的term是 call a function 而不是 invoke a f ...
- Centos7 Erlang Solutions 安装
https://www.erlang-solutions.com/resources/download.html Installation using repository 1. Adding rep ...
- Erlang模块ets翻译
概要: 内置的存储 描述: 这个模块是Erlang内置存储BIFs的接口.这些提供了在Erlang运行时系统中存储大量数据的能力,并且能够对数据进行持续的访问时间.(在ordered_set的情况下, ...
- 安装thrift全过程
为了研究基于thrift的RPC框架,其实,是想自己基于thrift写一个微服务的platform.首先就是安装Thrift,便于IDL架构生成java的接口文件.多的不说了,开始install的过程 ...
- C++ Core Guidelines
C++ Core Guidelines September 9, 2015 Editors: Bjarne Stroustrup Herb Sutter This document is a very ...
- 初探React,将我们的View标签化
前言 我之前喜欢玩一款游戏:全民飞机大战,而且有点痴迷其中,如果你想站在游戏的第一阶梯,便需要不断的练技术练装备,但是腾讯的游戏一般而言是有点恶心的,他会不断的出新飞机.新装备.新宠物,所以,很多时候 ...
随机推荐
- 关于Metadata Client Object Model 的一些操作
一.查询指定的Termset及子项 <script type="text/javascript" src="/Style%20Library/aaaa/Script ...
- 二、 java中的变量与数据类型及类型转换
标识符:凡是可以自己命名的地方都叫标识符,如:类名.方法名.接口名... 1.标识符命名的规则: 由26个英文字母大小写,0-9,_或$组成,不遵守会报错. 不可以用数字开头. 不能使用关键字和保留字 ...
- window10下用ZIP压缩包安装 mysql 8.0.11
1.下载地址 https://dev.mysql.com/downloads/mysql/ 2.解压后的文件目录如图,复制到指定的文件目录,如我的 E:\root\mysql-8.0.11-winx6 ...
- LeetCode OJ——Minimum Depth of Binary Tree
http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ 贡献了一次runtime error,因为如果输入为{}即空的时候,出现了c ...
- java parse 带英文单词的日期字符串(转化新浪微博api返回的时间)
String str = "Sun Sep 23 00:32:57 +0800 2012"; SimpleDateFormat dateFormat = new SimpleDat ...
- DevExpress控件GridControl使用 z
设置选中行的背景色.而不改变前景色. EnableAppearanceFocusedCell = False, EnableAppearanceFocusedRow = False private v ...
- C#文件路径操作总结【转】
http://www.cnblogs.com/zhoufoxcn/archive/2006/10/24/2515874.html 一.获取当前文件的路径 1. System.Diagnostics ...
- 微信小程序日期定位弹出框遮挡问题
只需要用bindtap绑定一个点击后的操作(隐藏键盘): wx.hideKeyboard()
- python(40)- 进程、线程、协程及IO模型
一.操作系统概念 操作系统位于底层硬件与应用软件之间的一层.工作方式:向下管理硬件,向上提供接口. 操作系统进行进程切换:1.出现IO操作:2.固定时间. 固定时间很短,人感受不到.每一个应用层运行起 ...
- Unsupported major.minor version (jdk版本错误)解决方案 办法
如果你遇到了 Unsupported major.minor version ,请认真看一下,说不定会有帮助. 我花两个小时总结的经验,你可能10分钟就得到了. ^**^ 一.错误现象: 当改变了jd ...