1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

概要

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?