title erlang 學習筆記
datetime 2017-03-15 16:02:05
tags erlang,note
category coding
link erlang-notes
file 2017-03-15-160205-erlang-notes
template post
end
- erl 就是 erlang's shell
- 離開erl的兩種方式: 1. ctrl + c, then press a; 2. halt().
- 程式用 "." 結束,例如: 2 + 3.
- help(). 顯示所有指令。
一個erl的檔案長得像下面這個樣子:
tut.erl-module(tut).
-export([double/1]).
double(X) ->
2 * X.
- 檔名(tut.erl)一定要與module的名稱(-module(tut).)一樣
-module(tut).
表示這個檔案是一個叫 tut 的module。-export([double/1]).
表示有一個叫 double 的funcation可以在module外被呼叫,它有一個參數在呼叫的時候要傳入。- 要注意double(X)的X必須是大寫,erlang中的變數必須是大寫開頭(capital)或是底線開頭的字串。
.erl 檔必須轉成 object code 才
-module(tut1).
-export([fac/1, mult/2]).
fac(1) ->
1;
fac(N) ->
N * fac(N - 1).
mult(X, Y) ->
X * Y.
- ";" 表示有一個以上叫 fac 的funcation。