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. SPOJ QTREE4 - Query on a tree IV

    You are given a tree (an acyclic undirected connected graph) with N nodes, and nodes numbered 1,2,3. ...

  2. POJ3067 Japan

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26270   Accepted: 7132 Description Japa ...

  3. 【CF1027B】Numbers on the Chessboard(数学)

    题意:给定一个n*n的矩阵与生成矩阵的方式,多次询问同一个方格内(x,y)的数字是多少 题意:浪费人生的矩阵题,找规律 #include<cstdio> #include<cstri ...

  4. 转 python语法学习面向对象之继承

    传送门 python语法学习面向对象之继承 只要涉及到面向对象,”类“是必须出现的一个代名词. 类和对象是面向对象编程的两个主要方面.类创建一个新类型,而对象是这个类的实例. 类的一些概念: 包括初始 ...

  5. 使用C语言和i2c-dev驱动

    原文地址:blog.csdn.NET/wyt2013/article/details/20740659 感谢作者分享. 在本博客的<使用Beaglebone Black的I2C(一)>中, ...

  6. Linux 之 LNMP服务器搭建-前期准备

    LNMP服务器搭建-前期准备 参考教程:[千峰教育] 系统环境: 系统:centos 6.8. 软件安装位置: (1)软件源代码包存放位置:/lnmp/src 命令:mkdir -p /lnmp/sr ...

  7. java 正则表达式-忽略大小写与多行匹配

    Pattern.compile("'.*?'", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);

  8. python 终端模拟模块 pexpect

    简单介绍pexpect是 Don Libes 的 Expect 语言的一个 Python 实现,是一个用来启动子程序,并使用正则表达式对程序输出做出特定响应,以此实现与其自动交互的 Python 模块 ...

  9. (2)Unity3d菜单

    1.文件菜单 2.编辑菜单 Frame Selected 焦点选择和双击Hierarchy中的元素一样的功能 Lock View to Selected  选中对象再点击此按钮,在场景视图中移动此对象 ...

  10. Codeforces635C XOR Equation【数学】

    题目链接: http://codeforces.com/contest/635/problem/C 题意: 给定两个数的和s及异或x,求两个数的可能情况. 分析: 我们有公式a+b=a& b∗ ...