Erlang真的是功能性语言吗? [英] Is Erlang really a functional language?
问题描述
中心思想是每个进程都是一个功能程序通过输入消息流。功能程序的结果是向其他人发送消息的输出流。从这个角度来看,Erlang是一个相当干净的功能语言;数据结构没有破坏性的更新(如Lisp和大多数Schema中的setcar)。
除了少数例外,所有内置函数(如ETS表上的操作)也都遵循这个模式:除了效率问题,这些BIF实际上可以用纯Erlang进程和消息传递来实现。
所以是的,Erlang语言是功能的,但是一个集合相互作用的Erlang过程是不同的。每个进程是一个持续的计算,因此它具有当前状态,这可以相对于其他进程而改变。即使是数据库也是这方面的另一个过程。
在我看来,这是Erlang最重要的事情之一:在进程之外,可能会有风暴肆虐,但在内部,事情是平静的,让你专注于这个过程应该做的 - 只有这样。
I hear all the time that Erlang is a functional language, yet it is easy to call databases or non side-effect free code from a function, and commands are easily ordered by using "," commas between them just like Ruby or another language, so where is the "functional" part of Erlang?
The central idea is that each process is a functional program over an input stream of messages. The result from the functional program is an output stream of messages to others. From this perspective, Erlang is a rather clean functional language; there are no destructive updates to data structures (like setcar in Lisp and most Schemes).
With few exceptions, all built-in functions such as operations on ETS tables also follow this model: apart from efficiency issues, those BIFs could actually have been implemented with pure Erlang processes and message passing.
So yes, the Erlang language is functional, but a collection of interacting Erlang processes is a different thing. Each process is an ongoing computation, and as such it has a current state, which can change in relation to the other processes. Even a database is just another process in this respect.
In my mind, this is one of the most important things about Erlang: outside the process, there could be a storm raging, but inside, things are calm, letting you focus on what that process should do - and only that.
这篇关于Erlang真的是功能性语言吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!