1. 变量不可变, 大写字母开头为变量, 如果X = 4, 那么X = 7 将报错, X=4才是对的
2. 原子,小写字母开头或者双引号开始的字串或者数值为原子, “a” = a
3. 元组和列表, 元组: {person, {name,{first,joe}, {last,armst}}} 列表:[{apple,10}, {milk,30}]
4. $s 可获取字母s的数值115, [107 -3, $e, $l, $l, $o] 代表 “hello”
5. f() 会在shell中释放所有绑定变量
6. c:cd(“/home”) 或者 c:ls() 可直接执行shell命令
7. lists:map() 或者 lists:filter() 或者 lists:member()
8. ex>Fruit = [apple, pear,orange].
ex>MakeTest = fun(L)-> (fun(X)->lists:member(X, L) end) end.
ex>IsFruit = MakeTest(Fruit).
9. 列表提炼 [2 *X || X <- L].
10. Erlang中只有8种基本的数据类型:
Integer、float、atom、reference、fun、port、pid、bitstring
同时提供2种复合结构:tuple,list,这就是Erlang的所有数据类型
11. Vim,加入vim-erlang 和 taglist 插件后就是一个不错的IDE
12. try 表达式
try Expr
catch
throw:Term -> Term;
exit:Reason -> {‘EXIT’,Reason}
error:Reason -> {‘EXIT’,{Reason,erlang:get_stacktrace()}}
end.
13. 在Erlang中小于等于是用=<表示,而不是一般语言中的<=语法
14. and or 和andalso orelse的区别
and和or会计算两边的表达式,而andalso和orelse的求值采用短路机制,比如exp1 andalso exp2,当exp1返回false之后,就不会去求值
exp2,而是直接返回false,而exp1 and exp2会对exp1和exp2都进行求值,or与orelse也类似
15. length([1,2,3,4,5).
16. size({a,bc)
17. atom_to_list(atom).
18. list_to_tuple([1,2,3,4]).