Elixir

All

Intro

I remember the class of professor Ismar Frango, back in 2012 on Paradigms of programming. It was mind blowing to think recursively but to implement in C or C++ it was a bit tough. Nowadays, with python and elixir, dude! it’s much easier.

Elixir

I started learning Elixir some time back, when I make a mistake in one of my python programs and Elixir came with “end” in function. It was like, well, this is a broken python. But not, it’s much more than that.

To learn I use this blog [2] and this tutorial [1] It’s from there that I stole the code below. Elixir is very powerful for pattern matching [3].

defmodule Recursion do
  def print_multiple_times(msg, n) when n <= 1 do
    IO.puts msg
  end

  def print_multiple_times(msg, n) do
    IO.puts msg
    print_multiple_times(msg, n - 1)
  end
end

Recursion.print_multiple_times("Hello!", 3)

 

REFs

[1] https://www.youtube.com/watch?v=pBNOavRoNL0

[2] https://elixir-lang.org/getting-started/recursion.html

[3]https://medium.com/mobileforgood/5-things-we-like-about-elixir-coming-from-python-c19cbae7484d

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s