erlang有前途吗

Erlang is a functional programming language developed by Ericsson for use in telecom applications. Because they felt that it’s unacceptable for a telecom system to have any significant downtime, Erlang was built to be (among other things):

Erlang是爱立信开发的一种功能编程语言,用于电信应用程序。 因为他们认为电信系统出现任何严重的停机都是不可接受的,所以Erlang被设计为(除其他外):

  • distributed and fault-tolerant (a piece of failing software or hardware should not bring the system down)

    分布式且具有容错能力(出现故障的软件或硬件不应使系统宕机)

  • concurrent (it can spawn many processes, each executing a small and well-defined piece of work, and isolated from one another but able to communicate via messaging)

    并发(它可以产生许多进程,每个进程执行一个定义明确的小工作,并且彼此隔离,但能够通过消息传递进行通信)

  • hot-swappable (code can be swapped into the system while it’s running, leading to high availability and minimal system downtime)

    可热插拔(可以在运行时将代码交换到系统中,从而实现高可用性和最少的系统停机时间)

句法 (Syntax)

Erlang makes heavy use of recursion. Since data is immutable in Erlang, the use of while and for loops (where a variable needs to keep changing its value) is not allowed.

Erlang大量使用递归 。 由于数据在Erlang中是不可变的,因此不允许使用whilefor循环(变量需要不断更改其值)。

Here’s an example of recursion, showing how a function repeatedly strips the first letter from the front of a name and prints it, only stopping when the last letter has been encountered.

这是一个递归示例,展示了函数如何反复从名称的开头剥离第一个字母并进行打印,仅在遇到最后一个字母时才停止。

-module(name).-export([print_name/1]).print_name([RemainingLetter | []]) ->io:format("~c~n", [RemainingLetter]);
print_name([FirstLetter | RestOfName]) ->io:format("~c~n", [FirstLetter]),print_name(RestOfName).

Output:

输出:

> name:print_name("Mike").
M
i
k
e
ok

There is also a heavy emphasis on pattern-matching, which frequently eliminates the need for an if structure or case statement. In the following example, there are two matches for specific names, followed by a catch-all for any other names.

模式匹配也很受重视,它通常消除了对if结构或case语句的需要。 在下面的示例中,特定名称有两个匹配项,随后是所有其他名称的“包罗万象”。

-module(greeting).-export([say_hello/1]).say_hello("Mary") ->"Welcome back Mary!";
say_hello("Tom") ->"Howdy Tom.";
say_hello(Name) ->"Hello " ++ Name ++ ".".

Output:

输出:

> greeting:say_hello("Mary").
"Welcome back Mary!"
> greeting:say_hello("Tom").
"Howdy Tom."
> greeting:say_hello("Beth").
"Hello Beth."

Erlang术语存储 (Erlang Term Storage)

Erlang Term Storage, normally abbreviated as ETS, is an in-memory database built into OTP. It’s accessible within Elixir, and is a powerful alternative to solutions like Redis when your application runs on a single node.

Erlang Term Storage,通常缩写为ETS,是OTP中内置的内存数据库。 它可以在Elixir中访问,当应用程序在单个节点上运行时,它是Redis之类的解决方案的强大替代方案。

快速开始 (Quick Start)

To create an ETS table you first need to initialize a table tableName = :ets.new(:table_otp_name, []), once you have initialized a table you can: insert data, lookup values, delete data, and more.

要创建ETS表,首先需要初始化表tableName = :ets.new(:table_otp_name, []) ,一旦初始化了表,您可以:插入数据,查找值,删除数据等等。

IEX中的ETS演示 (ETS Demo in IEX)

iex(1)> myETSTable = :ets.new(:my_ets_table, [])
#Reference<0.1520230345.550371329.65846>
iex(2)> :ets.insert(myETSTable, {"favoriteWebSite", "freeCodeCamp"})
true
iex(3)> :ets.insert(myETSTable, {"favoriteProgrammingLanguage", "Elixir"})
true
iex(4)> :ets.i(myETSTable)
<1   > {<<"favoriteProgrammingLanguage">>,<<"Elixir">>}
<2   > {<<"favoriteWebSite">>,<<"freeCodeCamp">>}
EOT  (q)uit (p)Digits (k)ill /Regexp -->

坚持不懈 (Persistence)

ETS Tables are not persistent and are destroyed once the process which owns it terminates. If you would like to store data persistently a traditional database and/or file-based storage is recommended.

ETS表不是持久性的,一旦拥有它的进程终止,它就会被销毁。 如果您想永久存储数据,建议使用传统的数据库和/或基于文件的存储。

用例 (Use cases)

ETS Tables are commonly used for caching data in the application, for example account data fetched from a database may be stored in an ETS Table to reduce the amount of queries to the database. Another use case is for rate limiting use of features in a web application - ETS’s fast read and write speed make it great for this. ETS Tables are a powerful tool for developing highly concurrent web applications at the lowest possible hardware cost.

ETS表通常用于在应用程序中缓存数据,例如,从数据库中提取的帐户数据可以存储在ETS表中,以减少对数据库的查询量。 另一个用例是对Web应用程序中的功能进行限速使用-ETS的快速读写速度使其非常有用。 ETS表是用于以最低的硬件成本开发高度并发的Web应用程序的强大工具。

试试看 (Try it out)

There are websites where you can try running Erlang commands without having to install anything locally, like these:

在某些网站上,您可以尝试运行Erlang命令,而无需在本地安装任何内容,例如:

  • Give it a try! (a hands-on tutorial)

    试试看! (动手教程)

  • TutorialsPoint CodingGround

    教程点编码基础

If you’d like to install it on your (or a virtual) machine, you can find installation files at Erlang.org or on Erlang Solutions.

如果要将其安装在(或虚拟)计算机上,可以在Erlang.org或Erlang Solutions上找到安装文件。

更多信息: (More Information:)

  • About Erlang

    关于二郎

  • Erlang (programming language)

    Erlang(编程语言)

翻译自: https://www.freecodecamp.org/news/an-overview-of-erlang-with-examples/

erlang有前途吗

erlang有前途吗_带有示例的Erlang概述相关推荐

  1. python示例_带有示例的Python功能指南

    python示例 Python函数简介 (Introduction to Functions in Python) A function allows you to define a reusable ...

  2. python 示例_带有示例的Python File write()方法

    python 示例 文件write()方法 (File write() Method) write() method is an inbuilt method in Python, it is use ...

  3. lock_sh 示例_带有示例的Python date __str __()方法

    lock_sh 示例 Python date .__ str __()方法 (Python date.__str__() Method) date.__str__() method is used t ...

  4. python 示例_带有示例的Python文件关闭属性

    python 示例 文件关闭属性 (File closed Property) closed Property is an inbuilt property of File object (IO ob ...

  5. python 示例_带有示例的Python date timetuple()方法

    python 示例 Python date.timetuple()方法 (Python date.timetuple() Method) date.timetuple() method is used ...

  6. python 示例_带有示例的Python date isocalendar()方法

    python 示例 Python date.isocalendar()方法 (Python date.isocalendar() Method) date.isocalendar() method i ...

  7. python 示例_带有示例的Python字典update()方法

    python 示例 字典update()方法 (Dictionary update() Method) update() method is used to update the dictionary ...

  8. java 方法 示例_带有示例的Java EnumSetSupplementOf()方法

    java 方法 示例 EnumSet类complementOf()方法 (EnumSet Class complementOf() method) complementOf() method is a ...

  9. python 示例_带有示例的Python字典popitem()方法

    python 示例 字典popitem()方法 (Dictionary popitem() Method) popitem() method is used to remove random/last ...

最新文章

  1. Linux-gate.so.1的含义[ZZ]
  2. 【大会】除了FFmepg和WebRTC,还有哪些新工具?
  3. springboot+IntelliJ IDEA实现热部署
  4. Linux部署oracle11g,linux环境下部署Oracle11g
  5. linux如何检测文件完整,shell脚本实现linux系统文件完整性检测
  6. 凸优化第五章对偶 5.3 几何解释
  7. 解决Linux无法读写U盘中的NTFS问题
  8. CF1442D Sum 分治 背包dp
  9. 大学计算机基础网络配置实验报告答案,2008大学计算机基础实验报告参考答案...
  10. 用PS把一张图片变成素描画
  11. 【QImage类常用函数】
  12. JavaWeb学习笔记(HTML语言)
  13. 零基础学C语言设计难吗,【经验分享】零基础想学C语言,过来人提醒大家几点...
  14. 如何配置和测试ChatBot
  15. uniform对象及其使用
  16. Win10杀死进程方式
  17. android 音量调节框,Android 音量调节方法
  18. 教育行业的特斯拉,从无人驾驶到无人教学
  19. oracle 手机、身份证 打码 函数
  20. [转载]教练,我也想再要一个同桌

热门文章

  1. 【CVPR2019】论文完整列表一
  2. 修改线程的名称 java 1615387415
  3. Java 控制台程序的基本结构测试分析草稿
  4. 前端开发 margin外边距 0229
  5. 16-mysql-dml语言-增删改数据
  6. centos7-安装redis-教程190923-精准版
  7. python-带参数的装饰器
  8. python-装饰器简介
  9. Go:获取命令行参数
  10. SAP编程中最基本的概念