ヽ(´・肉・`)ノログ

How do we fighting without fighting?

すごいE本をElixirでやる(2)

つづき

1 章

1.2 Erlang の基礎をいくつか

数値型

Erlang と違うところ

/Users/niku% iex
Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (0.14.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 2 + 15
17
iex(2)> 49 * 100
4900
iex(3)> 1892 - 1472
420
iex(4)> 5 / 2
2.5
iex(5)> div 5, 2
2
iex(6)> rem 5, 2
1
iex(7)> (50 * 100) - 4999
1
iex(8)> -(50 * 100 - 4999)
-1
iex(9)> -50 * (100 - 4999)
244950
iex(10)> 0b101010
42
iex(11)> 0677
447
iex(12)> 0xae
174

変化できない変数

Erlang と違うところ

/Users/niku% iex
Erlang/OTP 17 [erts-6.1] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (0.14.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> one
** (RuntimeError) undefined function: one/0

iex(1)> one = 1
1
iex(2)> un = uno = one = 1
1
iex(3)> two = one + one
2
iex(4)> two = 2
2
iex(5)> two = two + 1
3
iex(6)> two
3
iex(7)> two = 2
2
iex(8)> ^two = two + 1
** (MatchError) no match of right hand side value: 3

iex(8)> ^two = one + 1
2
iex(9)> 47 = 45 + 3
** (MatchError) no match of right hand side value: 48
iex(9)> Two = 2
** (MatchError) no match of right hand side value: 2
iex(9)> f(two)
** (RuntimeError) undefined function: f/1