概要
Elixirの対話モードでErlangとの相互運用の動作を確認してみました。以下のページを参考にしました。
対話モードで実行
以下のコマンドを実行しました。
$ 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)> defmodule Example do
...(1)> def timed(fun, args) do
...(1)> {time, result} = :timer.tc(fun, args)
...(1)> IO.puts("Time: #{time} μs")
...(1)> IO.puts("Result: #{result}")
...(1)> end
...(1)> end
{:module, Example,
<<70, 79, 82, 49, 0, 0, 6, 232, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 207,
0, 0, 0, 22, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 109, 112, 108,
101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, {:timed, 2}}
iex(2)> Example.timed(fn (n) -> (n * n) * n end, [100])
Time: 14 μs
Result: 1000000
:ok
iex(3)> is_list('Example')
true
iex(4)> is_list("Example")
false
iex(5)> is_binary("Example")
true
iex(6)> <<"Example">> === "Example"
true
iex(7)> x = 10
10
iex(8)> x = 20
20
iex(9)> x1 = x + 10
30
iex(10)>
まとめ
何かの役に立てばと。