elixir - 3. 基础数据类型
访问量: 1402
类型:
1 interger
"abc" string
:hi symbol, ( atom)
[1,2,3] array
{1,2,3} tuple
1.0 float
true/false boolean
基本方法:
String.length("hi")
is_integer(1) # => true
is_boolean("lala") # => false
定义默认方法:
iex(15)> add = fn a,b ->
...(15)> a + b
...(15)> end
调用: add.(2,3) # => 5
is_function(add) #=> true
数组操作:
iex(18)> [1,2,3]
[1, 2, 3]
iex(19)> length [1,2,3]
3
iex(20)> [1,2,3] ++ [4,5]
[1, 2, 3, 4, 5]
iex(21)> [1,2,2,3,4] -- [1,4]
[2, 2, 3]
'hello' 表示一个 charset
"hello" 表示一个String