How do I run a beam file compiled by Elixir or Erlang?

前端 未结 3 542
一整个雨季
一整个雨季 2021-01-30 13:58

I have installed Erlang/OTP and Elixir, and compiled the HelloWorld program into a BEAM using the command:

elixirc test.ex

Which produced a fil

3条回答
  •  逝去的感伤
    2021-01-30 14:38

    Assume that I write an Elixir program like this:

    defmodule PascalTriangle do
      defp next_row(m), do: for(x <- (-1..Map.size(m)-1), do: { (x+1), Map.get(m, x, 0) + Map.get(m, x+1, 0) } ) |> Map.new
      def draw(1), do: (IO.puts(1); %{ 0 => 1})
      def draw(n) do
        (new_map = draw(n - 1) |> next_row ) |> Map.values |> Enum.join(" ") |> IO.puts
        new_map
      end
    end
    

    The module PascalTriangle can be used like this: PascalTriangle.draw(8)

    When you use elixirc to compile the ex file, it will create a file called Elixir.PascalTriangle.beam.

    From command line, you can execute the beam file like this: elixir -e "PascalTriangle.draw(8)"

    You can see the output similar to the photo:

提交回复
热议问题