2016年6月6日月曜日

開発環境

Seven More Languages in Seven Weeks (Bruce Tate (著)、Ian Dees (著)、Frederic Daoud (著)、Jack Moffitt (著)、Pragmatic Bookshelf)のChapter 3(Elixir)、Day 1(Laying a Great Foundation)、Do (Easy)(No. 4220).を取り組んでみる。

Do (Easy)(No. 4220)

コード(Emacs)

#!/usr/bin/env elixir

point = {5, 10}
point1 = {0, 0}
point2 = {1, 2}
line = {point1, point2}
point3 = {1, 1}
circle = {point3, 10}
polygon = {{0, 0}, {2, 0}, {2, 1}, {1, 2}, {0, 1}}
triangle = {{0, 0}, {1, 0}, {0, 1}}

IO.puts "point: #{inspect point}\nline: #{inspect line}"
IO.puts "circle: #{inspect circle}\npolygone: #{inspect polygon}"
IO.puts "triangle: #{inspect triangle}"

hypotenuse = &(:math.sqrt(&1 * &1 + &2 * &2))

IO.puts "#{hypotenuse.(3, 4)}"

s = "Elixier"
a = String.to_atom(s)

IO.puts inspect s
IO.puts inspect a
Enum.each [s, a], &(
if is_atom(&1) do
  IO.puts :true
else
  IO.puts :false
end
)

入出力結果(Emacs, Terminal, elm repl)

$ ./easy.exs 
point: {5, 10}
line: {{0, 0}, {1, 2}}
circle: {{1, 1}, 10}
polygone: {{0, 0}, {2, 0}, {2, 1}, {1, 2}, {0, 1}}
triangle: {{0, 0}, {1, 0}, {0, 1}}
5.0
"Elixier"
:Elixier
false
true
$

0 コメント:

コメントを投稿

Comments on Google+: