• erlang 入门(1)


    erl
    - 命令以.结尾
    - %为注释
    - 变量必须大写开头 X = 12.
    - [1,3.4,true] is a list and {person, 25, "Jason"} is a tuple.
    - tuple赋值orpattern match
    {ip, IP} = {ip, "192.168.0.1"}.
    {Atom, IP} = {ip, "192.168.0.1"}.  
    -variable 和atom ,前者大写开头,后者小写开头
    - loops are done through recursion
    如下例
    -module(factorial).
    -export([factorial/1]).

    factorial(0) -> 1.
    factorial(N) ->
        N * factorial(N-1).
    - 加减乘除都为实数支持大整数,求余为rem  div    
    - 变量名被赋值后,不允许被再次定义
    9> Two = 2.  
    2  
    10> two = 3.  
    ** exception error: no match of right hand side value 3  
    11> Two = 3.  
    ** exception error: no match of right hand side value 3

    -清除变量
      f(变量名) -- 清除对该变量的赋值
      f().      -- 清除所有变量的赋值
     
    - .and 和 or 都会计算两边的值 ,若是你期望只做一个短路运算的话 ,那么就需要用到 andalso 好 orelse .这个就是类似于 java的 && || 运算符!
     
    - 1.=:= 等同于其他语言中的 == 。  =/=和/= 等同于其他语言中的 !=  这个地方还有疑问!
    2.从上面的解析看, =:=比较的类似于java中的内存地址比较 == 比较的是两个地址的值是否相同!
    3.其他的还有就是 >= =<

        56> 5 == 5.0.  
        true  
        57> 5 =:= 5.  
        true  
        58> 1=/=0.  
        true  
        59> 1=:=0.  
        false  
        60> 5=:=5.0.  
        false  
        61> 5==5.0.  
        true  
        62> 1/=3.  
        true  

        66> 1 >= 1.  
        true  
        67> 1 =< 1.  
        true  
        68> 1 > 3.  
        false  
        69> 1 < 3.  
        true  

        77> 5 =:= false.  
        false  
        78> 5 ==false.  
        false  

        79> 1 == false.  
        false  
        80> 1 < false.  
        true  

    在erlang中没有 true和false的布尔类型变量。 这里的 true 和 false 都是 atom.原子单一的变量(可能描述的不准确)。
    在erlang中不同类型之间的比较关系如下所示:
    Java代码  收藏代码

        number < atom < reference < fun < port < pid < tuple < list < bit string

    —— _可以匹配任何变量
    6> {_,_,A}={12,23,222}.
    {12,23,222}
    7> A.
    222
    8> _.
    * 1: variable '_' is unbound
       

  • 相关阅读:
    记录:将图片数据生成 tfrecords 文件并在训练使用时读取
    记录:EM 算法估计混合高斯模型参数
    记录:Ubuntu 18.04 安装 tensorflow-gpu 版本
    记录:tf.saved_model 模块的简单使用(TensorFlow 模型存储与恢复)
    记录:TensorFlow 中的 padding 方式
    mybatis list映射
    idea使用插件mybatis-generator-plus生成mapper文件(mysql亲测可用)
    Element-UI树形表格
    Mysql5.7版本ERROR 1055问题
    为DISTINCT、GROUP BY和ORDER BY效率问题提提速
  • 原文地址:https://www.cnblogs.com/cutepig/p/2326011.html
Copyright © 2020-2023  润新知