LoginSignup
1
0

More than 1 year has passed since last update.

paiza.ioでelixir その43

Posted at

概要

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]

成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0