IO.puts(Math.sum(1, 2))
q = :queue.new q = :queue.in("A", q) q = :queue.in("B", q) {{:value, val}, q} = :queue.out(q) IO.puts(val) {{:value, val}, q} = :queue.out(q) IO.puts(val)
# Value of pi IO.puts(:math.pi()) # Logarithm IO.puts(:math.log(7.694785265142018e23)) # Exponentiation IO.puts(:math.exp(55.0)) #...
digraph = :digraph.new() coords = [{0.0, 0.0}, {1.0, 0.0}, {1.0, 1.0}] [v0, v1, v2] = (for c <- coords, do: :digraph.add_vertex(digraph, c)) :digraph.add_edge(digraph, v0, v1) :digraph.add_edge(digraph, v1, v2) for point <- :digraph.get_short_path(digraph, v0, v2) do {x, y} = point IO.puts("#{x}, #{y}") end
IO.puts(Base.encode16(:crypto.hash(:sha256, "Elixir")))
val = try do exit "I am exiting" catch :exit, _ -> "not really" end IO.puts(val)
val = try do Enum.each 20..100, fn(x) -> if rem(x, 13) == 0, do: throw(x) end "Got nothing" catch x -> "Got #{x}" end IO.puts(val)
err = try do 1 + "Hello" rescue RuntimeError -> "You've got a runtime error!" ArithmeticError -> "You've got a Argument error!" end IO.puts(err)
err = try do raise "oops" rescue e in RuntimeError -> e end IO.puts(err.message)
defmodule GreetBehaviour do @callback say_hello(name :: string) :: nil @callback say_bye(name :: string) :: nil end defmodule EnglishGreet do @behaviour GreetBehaviour def say_hello(name), do: IO.puts("Hello " <> name) def say_bye(name), do: IO.puts("Goodbye, " <> name) end defmodule SpanishGreet do @behaviour GreetBehaviour def say_hello(name), do: IO.puts("Hola " <> name) def say_bye(name), do: IO.puts("Adios " <> name) end EnglishGreet.say_hello("Ayush") EnglishGreet.say_bye("Ayush") SpanishGreet.say_hello("Ayush") SpanishGreet.say_bye("Ayush")
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more