DAY 9
0
Software Development

## 註解

``````# 註解
do_something() # 也可以放在行尾
``````

## 數字及其運算

``````1 # 整數
0b1010 #整數，2 進位
0o777 #整數，8 進位
0x1F #整數，16 進位

1.5 #浮點數
1.0e-10 #浮點數，科學計號表示法
``````

``````1 + 2 #=> 3
10 * 10 #=> 100
6 / 3 #=> 2.0
``````

``````div(6, 3) #=> 2
rem(6, 5) #=> 1
``````

`round/1` 可以將浮點數四捨五入，`trunc/1` 則可以取得整數的部份：

``````round(3.5) #=> 4
round(3.46, 3) #=> 4
trunc(3.8) #=> 3
``````

## 布林值

`ture``false`

``````false and 0
#=> false

true and 1
#=> 1

is_atom(100) or 2
#=> 2

1 and true
#=> ** (BadBooleanError) expected a boolean on left-side of "and", got: 1
``````

``````1 || false
#=> 1

nil && 10
#=> nil
``````

## Atom

Atom 是常數，長得像這樣 `:foo`。當宣告了一個 atom 後，整個應用程式將從此參考同一個值。在 Ruby 裡一樣的型別叫做 symbol 。

``````true == :true
#=> true
is_atom(false)
#=> true
``````

``````is_atom(MyModule)
#=> true

MyModule == :"Elixir.MyModule"
#=> true
``````

## 字串

``````"This is a string"

i = 5
"I need #{i} apples"
``````

``````s = "hełło"
is_bitstring(s)
#=> true
``````

``````"Hello" <> " world"
#=> "Hello world"
``````

``````"Hello " <> name = "Hello Tai"
#=> name = "Tai"
``````

## 比大小

``````number < atom < reference < function < port < pid < tuple < map < list < bitstring
``````

Happy hacking! 明天見。