Question

defmodule Math do
  def sum(a, b) do
    a + b
  end
end

I created this elixir module and created the byte code using command elixirc file.ex. I need to call the Math.sum() from another program using the bytecode. Can I call this method in a java program using

String startErlangVM = "iex";
Runtime.getRuntime().exec(startErlangVM + ";" + "Math.sum(1, 2)" );

But this isn't working. Is there any way to call a Elixir method not calling iex to start Erlang virtual machine explicitly?

Était-ce utile?

La solution

I want to run a program with multi-core support. Front end is in java. But java VM doesn't support parallel programming. Only one thread will run at a time. Elixier is better in parallel programming. So I tried to create the back end using elixir. I need help on calling the elixir methods.

In this case, to use the power of concurrency, you should implement the Java front end as a TCP client. And implement the Elixir backend as a TCP server, that is handling client requests and respond with messages.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top