DEV Community

Vee Satayamas
Vee Satayamas

Posted on

My first program in Elixir

10 มีนาคม 2562

I ported my program for showing concurrency from Erlang to Elixir. I guess this is still not Idiomatic Elixir. 😅

defmodule Con1 do
  def log(p, i) when rem(i, 3000) == 0 do
    IO.puts "#{p} #{i}"
  end
  def log(_, _) do
    :ok
  end

  def cnt(_, 0) do
    :ok
  end
  def cnt(p, i) do
    log(p, i)
    cnt(p, i - 1)
  end

  def par_cnt(0) do
    :ok
  end
  def par_cnt(n) do
    spawn fn() -> cnt(n, 3000000) end
    par_cnt(n - 1)
  end
end
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
talk2megooseman profile image
Erik Guzman

You gotta start somewhere, congrats on making something.