概要
paiza.ioでelixirやってみた。
変数のスコープ調べてみた。
サンプルコード
defmodule Main do
stack = []
stack = stack ++ [5]
Enum.map(String.split("9 9 - 9 9 / .", " "), fn s ->
#IO.puts s
stack = stack ++ [6]
IO.inspect stack
end)
stack = stack ++ [2]
IO.inspect stack
end
IO.puts ""
defmodule Main do
stack = []
stack = stack ++ [5]
s = String.split("9 9 - 9 9 / .", " ")
n = length(s) - 1
#IO.puts n
#IO.inspect s
for i <- 0..n do
#IO.puts Enum.at(s, i)
stack = stack ++ [6]
IO.inspect stack
end
stack = stack ++ [2]
IO.inspect stack
end
実行結果
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 2]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 6]
[5, 2]
成果物
以上。