Elixirの対話モードで型の基本の動作を確認してみた

# 概要
Elixirの対話モードで型の基本の動作を確認してみました。以下のページを参考にしました。

https://dev.to/gumi/elixir-02--30n1

# 対話モードで実行
以下のコマンドを実行しました。
```
$ iex
Erlang/OTP 24 [erts-12.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [jit]

Interactive Elixir (1.12.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> (1 + 2) * 3 - 4
5
iex(2)> 10 / 2
5.0
iex(3)> div(10, 2)
5
iex(4)> div 10, 2
5
iex(5)> rem 10, 3
1
iex(6)> 0b1000
8
iex(7)> 0o10
8
iex(8)> 0xFF
255
iex(9)> 1.0
1.0
iex(10)> 3.14e-2
0.0314
iex(11)> round(2.718)
3
iex(12)> trunc(2.718)
2
iex(13)> true
true
iex(14)> 1 > 2
false
iex(15)> is_boolean(1 > 2)
true
iex(16)> is_boolean(1)
false
iex(17)> h is_number/1

                              def is_number(term)                               

  @spec is_number(term()) :: boolean()

guard: true

Returns true if term is either an integer or a floating-point number; otherwise
returns false.

Allowed in guard tests. Inlined by the compiler.

iex(18)> :hello
:hello
iex(19)> :hello == :world
false
iex(20)> true == :true
true
iex(21)> is_atom(false)
true
iex(22)> is_boolean(:false)
true
iex(23)> is_atom(String)
true
iex(24)> is_atom(MyModule)
true
iex(25)> :math.pow(2, 3)
8.0
iex(26)> is_atom(:math)
true
iex(27)> "hello"
"hello"
iex(28)> "拝啓"
"拝啓"
iex(29)> "hello #{:world}"
"hello world"
iex(30)> "hello
...(30)> world"
"hello\nworld"
iex(31)> "hello\nworld"
"hello\nworld"
iex(32)> IO.puts "hello\nworld"
hello
world
:ok
iex(33)> is_binary("hello")
true
iex(34)> byte_size("hello")
5
iex(35)> byte_size("拝啓")
6
iex(36)> String.length("hello")
5
iex(37)> String.length("拝啓")
2
iex(38)> sum = fn (a, b) -> a + b end
#Function<43.65746770/2 in :erl_eval.expr/5>
iex(39)> sum.(1, 2)
3
iex(40)> is_function(sum)
true
iex(41)> is_function(sum, 1)
false
iex(42)> is_function(sum, 2)
true
iex(43)> sum = &(&1 + &2)
&:erlang.+/2
iex(44)> sum.(3, 4)
7
iex(45)> double = fn (a) -> sum.(a, a) end
#Function<44.65746770/1 in :erl_eval.expr/5>
iex(46)> double.(2)
4
iex(47)> x = 0
0
iex(48)> (fn -> x = 1 end).()
warning: variable "x" is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used)
  iex:48

1
iex(49)> x
0
iex(50)> list = [3.14, :pie, true, "Apple"]
[3.14, :pie, true, "Apple"]
iex(51)> length(list)
4
iex(52)> list ++ ["Cherry"]
[3.14, :pie, true, "Apple", "Cherry"]
iex(53)> ["π"] ++ list
["π", 3.14, :pie, true, "Apple"]
iex(54)> list -- [true, false]
[3.14, :pie, "Apple"]
iex(55)> [1, 1, 2, 1, 2, 3, 1, 2, 3, 4] -- [4, 1, 3, 1, 2]
[1, 2, 1, 2, 3]
iex(56)> hd(list)
3.14
iex(57)> tl(list)
[:pie, true, "Apple"]
iex(58)> hd([])
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a nonempty list

    :erlang.hd([])
iex(58)> tl([1])
[]
iex(59)> tl([])
** (ArgumentError) errors were found at the given arguments:

  * 1st argument: not a nonempty list

    :erlang.tl([])
iex(59)> [head | tail] = list
[3.14, :pie, true, "Apple"]
iex(60)> head
3.14
iex(61)> tail
[:pie, true, "Apple"]
iex(62)> [10, 11, 12]
'\n\v\f'
iex(63)> [104, 101, 108, 108, 111]
'hello'
iex(64)> i('hello')
Term
  'hello'
Data type
  List
Description
  This is a list of integers that is printed as a sequence of characters
  delimited by single quotes because all the integers in it represent printable
  ASCII characters. Conventionally, a list of Unicode code points is known as a
  charlist and a list of ASCII characters is a subset of it.
Raw representation
  [104, 101, 108, 108, 111]
Reference modules
  List
Implemented protocols
  Collectable, Enumerable, IEx.Info, Inspect, List.Chars, String.Chars
iex(65)> 'hello' == "hello"
false
iex(66)> i("hello")
Term
  "hello"
Data type
  BitString
Byte size
  5
Description
  This is a string: a UTF-8 encoded binary. It's printed surrounded by
  "double quotes" because all UTF-8 encoded code points in it are printable.
Raw representation
  <<104, 101, 108, 108, 111>>
Reference modules
  String, :binary
Implemented protocols
  Collectable, IEx.Info, Inspect, List.Chars, String.Chars
iex(67)> tuple = {3.14, :pie, true, "Apple"}
{3.14, :pie, true, "Apple"}
iex(68)> tuple_size(tuple)
4
iex(69)> elem(tuple, 3)
"Apple"
iex(70)> put_elem(tuple, 3, "Cherry")
{3.14, :pie, true, "Cherry"}
iex(71)> tuple
{3.14, :pie, true, "Apple"}
iex(72)> list = [1, 2, 3]
[1, 2, 3]
iex(73)> [0] ++ list
[0, 1, 2, 3]
iex(74)> list ++ [4]
[1, 2, 3, 4]
iex(75)> tuple = {:a, :b, :c, :d}
{:a, :b, :c, :d}
iex(76)> put_elem(tuple, 2, :e)
{:a, :b, :e, :d}
iex(77)> File.read("file")
{:ok, "This is a file.\n"}
iex(78)> File.read("file2")
{:error, :enoent}
iex(79)> tuple = {:ok, "hello"}
{:ok, "hello"}
iex(80)> elem(tuple, 1)
"hello"
iex(81)> 
```

# まとめ
何かの役に立てばと。