erlang学习笔记(1)

提示符
erl

注释
% comment

表达式
123456789 * 123456789.

变量(单一赋值)
X = 123456789.
X.
Y = X * X * X.
Y.
f().

整数
浮点数
X = 5 div 3.
Y = 5 rem 3.
Z = 5 / 3.
A = 3.14 * R * R.
字符 & 字符串(列表一种 必须使用"")
定义 & 赋值
Name = "hello".
Name = [$h, $e, $l, $l, $o].
提取
[83, 117, X, 112, 114, 105, 115, 101] = "Surprise".
X = $r.

常量
数值常量 5 3
原子(_ @)
red december cat zhangl@woobest a_long_name
'Moday' 'a' '+' 'an atom with space'

其他
元组(结构体)
定义 & 赋值
F = {firstname, joe}.
L = {lastname, armstrong}.
P = {persom, F, L}.
提取
{firstname, X} = F.
X.
{_, {_,X}, {_,Y}} = P.
X.
Y.
XXX
Point = {point, 10, 20}.
{point,C,C} = Point.

列表
[{apples, 10}, {pears, 6}, {milk, 3}].
[1+7, hello, {cost, apple, 10}].
[]是空列表
若T是列表,则[H | T]也是列表
定义 & 赋值
Things1=[{oranges, 4}, {apples, 10}, {milk, 3}].
Things2 = [{newspaper, 3} | Things1].
提取
[{newspaper, 3} | Things1] = Things2.
Things2.
[{oranges, X}, {_, _}, {_,_}] = Things1.
X.
OR
[{oranges, X}, _, _] = Things1.
X.

[Y, _, _] = Things1.
Y.
OR
[Y | _] = Things1.
Y.

[Z, _ | _] = Things1.
xxx
[Z, _] = Things1.

上一篇:HTML5移动Web开发(二)——配置移动开发环境以及简单示例


下一篇:Docker简介与安装配置