Erlang


Erlang (简体)

Erlang語言
編程范型: 多種范型:函數式、併發式
面市時間: 1987年
設計者: 愛立信
實作者: 愛立信
最近釋出日期: R12B-2/ 2008年4月
啟發語言: PrologLISP
影響語言: Scala
作業系統: SolarisSUSEMicrosoft WindowsVxWorks


Erlang是一種通用的面向併發的程式語言,它由瑞典電信設備製造商愛立信所轄的CS-Lab開發,目的是創造一種可以應對大規模併發活動的程式語言和運行環境。Erlang問世于1987年,經過十年的發展,于1998年發布開源版本。Erlang是運行於虛擬機解釋性語言,但是現在也包含有烏普薩拉大學高性能Erlang計劃(HiPE)[1]開發的本地代碼編譯器,自R11B-4版本開始,Erlang也開始支持腳本式解釋器。在編程范型上,Erlang屬於多重范型程式語言,涵蓋函數式、併發式及分散式

目錄

開發及演變歷史

Erlang得名于丹麥數學家統計學家Agner Krarup Erlang,同時Erlang還可以表示Ericsson Language。

發行版本

1998年起,Erlang發布開源版本,採用修改過的Mozilla公共許可證協議進行發放,同時愛立信仍然提供商業版本的技術支持。目前,Erlang最大的商業用戶是愛立信,其他知名用戶有北電網路Amazon.com以及T-Mobile[2]

當前的語言特徵

  • Fail-fast(中文譯為速錯),即盡可能快的暴露程序中的錯誤.
  • 面向併發的編程(COP concurrency-oriented programming).
  • 函數式編程
  • 弱類型
  • 腳本語言

函數式編程

Ering函數大致寫法如下,以一個求整數階乘的模塊為例:

-module(fact).
-export([fac/1]).

fac(0) -> 1;
fac(N) when N > 0 -> N * fac(N-1).

下面是快速排序演算法的一個Erlang實現:

%% quicksort:qsort(List)
%% Sort a list of items
-module(quicksort).
-export([qsort/1]).

qsort([]) -> [];
qsort([Pivot|Rest]) ->
    qsort([ X || X <- Rest, X <= Pivot]) ++ [Pivot] ++ qsort([ Y || Y <- Rest, Y > Pivot]).

併發及分散式編程

代碼示例如下:

% create process and call the function web:start_server(Port, MaxConnections)
ServerProcess = spawn (web, start_server, [Port, MaxConnections]),

% create a remote process and call the function web:start_server(Port, MaxConnections) on machine RemoteNode
RemoteProcess = spawn(RemoteNode, web, start_server, [Port, MaxConnections]),

% send the {pause, 10} message (a tuple with an atom "pause" and a number "10") to ServerProcess (asynchronously)
ServerProcess ! {pause, 10},

% receive messages sent to this process
receive       
        a_message -> do_something; 
        {data, DataContent} -> handle(DataContent);
        {hello, Text} -> io:format("Got hello message: ~s", [Text]);
        {goodbye, Text} -> io:format("Got goodbye message: ~s", [Text])
end.

參見

參考資料

  1. ^ High Performance Erlang.於2008年4月13日查閱.
  2. ^ Who uses Erlang for product development?.Frequently asked questions about Erlang.於2008年4月13日查閱. 「The largest user of Erlang is Ericsson. Ericsson use it to write software used in telecommunications systems. Many (dozens) projects have used it, a particularly large one is the extremely scalable AXD301 ATM switch.」 FAQ中列出的其他用戶包括: Nortel、Deutsche Flugsicherung、T-Mobile等

外部連結


! __







Why are we here?
All text is available under the terms of the GNU Free Documentation License
This page is cache of Wikipedia. History