当前位置: 首页 > news >正文

Erlang notes[2]

文章目录

  • standard modules
  • Matching, Guards, and Scope of Variables
  • references

standard modules

  1. as similar as other popular programming language,Erlang also has itself standard modules to help programmer finish regular works.
  2. the io module can be able to serve programmer to write some formatted input/output.if you has any question,the h(module name) command will be your relaible assistant.
  3. the format function take two lists as parameters,the first one is the formatted string,and the second one will be fill in these format symbols which are insided the firt list such as ~w ~w.for example:
io:format("it is so cool~n", []).
io:format("nice to ~w ~w~n", [meet , you]).

Matching, Guards, and Scope of Variables

  1. the when sentence will be executed immediately as long as it’s following conditions are satisfied.
    for example,this erlang program count the number of odd number in the list.
-module(hello).
-export([list_amount/1]).
%the list_amount function can get the number of odd number in a list.list_amount(Num_List) ->list_amount(Num_List,0).
list_amount([], Sum_result) ->Sum_result;
list_amount([Head|Rest], Sum_result) when Head rem 2 =:= 1;Head rem 2 =:= -1 ->list_amount(Rest,Sum_result+1),io:format("~w ~n",[Head]);
list_amount([Head|Rest], Sum_result)  when Head rem 2 =:= 0 ->list_amount(Rest,Sum_result).
25> c(hello).
{ok,hello}
26> hello:list_amount([11,33,53,22]).
53
33
11
ok
27> hello:list_amount([11,33,53,22,-23]).
-23
53
33
11
ok
28> hello:list_amount([11,33,53,22,-23,-102]).
-23
53
33
11
ok
29>

the above example illustrates how to apply the when ,which actually is guard,when the guard is true, the following code will be run.
there are a lot of useful operators can be used in guards as follows.

< less than
> greater than
== equal
>= greater or equal
=< less or equal
/= not equal

references

  1. https://www.erlang.org/doc/
http://www.lryc.cn/news/622491.html

相关文章:

  • Shortest Routes II(Floyd最短路)
  • 数据结构:二叉树的表示方式(Representation of Binary Trees)
  • 【100页PPT】数字化转型集团信息化总体解决方案(附下载方式)
  • UI-TARS-Desktop 产品发展史:从实验室原型到企业级解决方案
  • gulimall项目笔记:P54三级分类拖拽功能实现
  • 深入理解C++正则表达式:从基础到实践
  • ramdisk内存虚拟盘(一)——前世今生
  • Python爬取推特(X)的各种数据
  • 功能组和功能组状态的概念关系和区别
  • 【揭秘红黑树:高效数据结构解析】
  • 谈谈《More Effective C++》的条款30:代理类
  • JavaScript 防抖(Debounce)与节流(Throttle)
  • Python入门第2课:变量、数据类型与输入输出
  • MySQL(多表查询练习)
  • C#控制台输入(Read()、ReadKey()和ReadLine())
  • 【大模型微调系列-01】 入门与环境准备
  • Linux信号保存
  • PowerShell 格式化系统完全掌握(上):工作原理、默认规则与三大格式化命令
  • 【数据分享】上市公司创新韧性数据(2007-2023)
  • 数据处理分析环境搭建+Numpy使用教程
  • MySQL、PolarDB、PolarDB-X、TableStore、MongoDB、TiDB、ClickHouse选型
  • CIAIE 2025上海汽车内外饰展观察:从美学到功能的产业跃迁
  • 中级统计师-会计学基础知识-第一章 账户与复试记账
  • imx6ull-驱动开发篇25——Linux 中断上半部/下半部
  • 嵌入式学习 day52 IMX6ULL裸机开发-I2C
  • Redis核心应用场景及代码案例
  • WordPress 7B2主题,在使用PHP 8.0+出现502的解决办法。
  • 【机器学习深度学习】OpenCompass 评测指标全解析:让大模型评估更科学
  • platform总线注册流程分析
  • 洛谷 P2842 纸币问题 1 -普及-