在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 區(qū)塊鏈/ 輸出至終端
注冊進程名稱
錯誤處理
完整示例
分布式編程
消息傳遞
if 與 case
健壯性
映射 (Map)
高階函數(shù) (Fun)
輸出至終端
更多關于列表的內(nèi)容
內(nèi)置函數(shù) (BIF)
模塊與函數(shù)
將大程序分在多個文件中
匹配、Guards 與變量的作用域
超時
列表
完整示例
頭文件
標準模塊與使用手冊
進程
記錄
增加健壯性后的完整示例
Erlang Shell
原子類型

輸出至終端

用例子來說明如何格式化輸出到終端再好不過了,因此下面就用一個簡單的示例程序來說明如何使用 io:format 函數(shù)。與其它導出的函數(shù)一樣,你可以在 shell 中測試 io:format 函數(shù):

31> io:format("hello world~n", []).
hello world
ok
32> io:format("this outputs one Erlang term: ~w~n", [hello]).
this outputs one Erlang term: hello
ok
33> io:format("this outputs two Erlang terms: ~w~w~n", [hello, world]).
this outputs two Erlang terms: helloworld
ok
34> io:format("this outputs two Erlang terms: ~w ~w~n", [hello, world]).
this outputs two Erlang terms: hello world
ok

format/2 (2 表示兩個參數(shù))接受兩個列表作為參數(shù)。一般情況下,第一個參數(shù)是一個字符串(前面已經(jīng)說明,字符串也是列表)。除了 ~w 會按順序被替換為第二個列表中的的項以外,第一個參數(shù)會被直接輸出。每個 ~n 都會導致輸出換行。如果正常輸出,io:formate/2 函數(shù)會返回個原子值 ok。與其它 Erlang 函數(shù)一樣,如果發(fā)生錯誤會直接導致函數(shù)崩潰。這并 Erlang 系統(tǒng)中的錯誤,而是經(jīng)過深思熟慮后的一種策略。稍后會看到,Erlang 有著非常完善的錯誤處理機制來處理這些錯誤。如果要練習,想讓 io:format 崩潰并不是什么難事兒。不過,請注意,io:format 函數(shù)崩潰并不是說 Erlang shell 本身崩潰了。

上一篇:頭文件下一篇:進程