<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Weslei Juan Novaes Pereira</title>
    <description>The latest articles on DEV Community by Weslei Juan Novaes Pereira (@wesleimp).</description>
    <link>https://dev.to/wesleimp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F223841%2F1f081879-7c6a-43b9-8228-5ccf036220a9.jpeg</url>
      <title>DEV Community: Weslei Juan Novaes Pereira</title>
      <link>https://dev.to/wesleimp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wesleimp"/>
    <language>en</language>
    <item>
      <title>Elixir and Erlang code in the same umbrella project</title>
      <dc:creator>Weslei Juan Novaes Pereira</dc:creator>
      <pubDate>Tue, 30 Mar 2021 18:58:26 +0000</pubDate>
      <link>https://dev.to/wesleimp/elixir-and-erlang-code-in-the-same-project-2l83</link>
      <guid>https://dev.to/wesleimp/elixir-and-erlang-code-in-the-same-project-2l83</guid>
      <description>&lt;p&gt;There's a simple way to write the Elixir and Erlang codes under the same umbrella project and you can use them together.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Create a new umbrella project
&lt;/h1&gt;

&lt;p&gt;For this example, I'll create an umbrella project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; mix new ping_beam &lt;span class="nt"&gt;--umbrella&lt;/span&gt;
&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;ping_beam
&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; tree
&lt;span class="nb"&gt;.&lt;/span&gt;
├── apps
├── config
│  └── config.exs
├── mix.exs
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  2. Create an Elixir project in umbrella
&lt;/h1&gt;

&lt;p&gt;I'll start off by creating an Elixir project inside the &lt;code&gt;apps&lt;/code&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; mix new ping_elixir
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I'll add a &lt;code&gt;ping&lt;/code&gt; function inside the &lt;code&gt;PingElixir&lt;/code&gt; module whose only purpose is to print out a message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# apps/ping_elixir/lib/ping_elixir.ex&lt;/span&gt;
&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;PingElixir&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;@moduledoc&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;ping&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;puts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Ping from Elixir"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  3. Create an Erlang project in umbrella
&lt;/h1&gt;

&lt;p&gt;I'll create an Erlang project using &lt;code&gt;rebar3&lt;/code&gt; also inside the &lt;code&gt;apps&lt;/code&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; rebar3 new lib ping_erlang
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As for the Elixir project, I'll also create a module and add a &lt;code&gt;ping&lt;/code&gt; function there.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight erlang"&gt;&lt;code&gt;&lt;span class="c"&gt;% apps/ping_erlang/src/ping_erlang.erl
&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="ni"&gt;module&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ping_erlang&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;

&lt;span class="p"&gt;-&lt;/span&gt;&lt;span class="ni"&gt;export&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;ping&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;

&lt;span class="nf"&gt;ping&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s"&gt;"Ping from Erlang"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  4. Reference and use the projects above
&lt;/h1&gt;

&lt;p&gt;For this step, I'll create a new project named &lt;code&gt;ping&lt;/code&gt; where I'll create a &lt;code&gt;ping&lt;/code&gt; function and call the modules above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; mix new ping
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, I'll change the &lt;code&gt;mix.exs&lt;/code&gt; adding the &lt;code&gt;PingElixir&lt;/code&gt; and &lt;code&gt;ping_erlang&lt;/code&gt; modules as umbrella dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# apps/ping/mix.exs&lt;/span&gt;
defmodule Ping.MixProject &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="c"&gt;# project config...&lt;/span&gt;

  defp deps &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="o"&gt;[&lt;/span&gt;
      &lt;span class="o"&gt;{&lt;/span&gt;:ping_elixir, in_umbrella: &lt;span class="nb"&gt;true&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;,
      &lt;span class="c"&gt;# As the Erlang project, it's really important to add the manager as rebar3&lt;/span&gt;
      &lt;span class="o"&gt;{&lt;/span&gt;:ping_erlang, in_umbrella: &lt;span class="nb"&gt;true&lt;/span&gt;, manager: :rebar3&lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;]&lt;/span&gt;
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, I'll modify the ping module to call those modules.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elixir"&gt;&lt;code&gt;&lt;span class="c1"&gt;# apps/ping/lib/ping.ex&lt;/span&gt;
&lt;span class="k"&gt;defmodule&lt;/span&gt; &lt;span class="no"&gt;Ping&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;@moduledoc&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="n"&gt;ping&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="no"&gt;PingElixir&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ping&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
      &lt;span class="ss"&gt;:ping_erlang&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ping&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  5. Running
&lt;/h1&gt;

&lt;p&gt;And as for the testing of the code, it's pretty simple.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$&amp;gt;&lt;/span&gt; iex &lt;span class="nt"&gt;-S&lt;/span&gt; mix

iex&amp;gt; PingElixir.ping&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="s2"&gt;"Ping from Elixir"&lt;/span&gt;

iex&amp;gt; :ping_erlang.ping&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="s2"&gt;"Ping from Erlang"&lt;/span&gt;

iex&amp;gt; Ping.ping&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Ping from Elixir"&lt;/span&gt;, &lt;span class="s2"&gt;"Ping from Erlang"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  6. Conclusion
&lt;/h1&gt;

&lt;p&gt;It's a really simple process! Just put the Elixir and Erlang codes together. And with a few lines of code, you'll get it done.&lt;/p&gt;

&lt;p&gt;Check the &lt;a href="https://github.com/wesleimp/ping_beam"&gt;repo&lt;/a&gt; for more.&lt;/p&gt;

&lt;p&gt;Thanks!&lt;/p&gt;

</description>
      <category>elixir</category>
      <category>erlang</category>
    </item>
  </channel>
</rss>
