5 things you need to remember in Elixir

  1. Single quotes vs double quotes
    A lot of modern programming languages, like ruby, javascript and python, will treat'string' the same as"string" . In Elixir, however, it is not the case
> 'string' == "string"
false
> IEx.Info.info('string')
... {"Data type", "List"} ...
> IEx.Info.info("string")
... {"Data type", "BitString"} ...
defmodule AnimalSoundEmitter do
def emit(:dog), do: :bark
def emit(:cat), do: :meow
def emit(:snake), do: :hiss
def emit(:lion), do: :roar
end
defmodule Calculator do
def plus(a, b) when is_number(a) and is_number(b), do: a + b
def minus(a, b) when is_number(a) and is_number(b), do: a - b
def multiply(a, b) when is_number(a) and is_number(b), do: a * b
def divide(a, b) when is_number(a) and is_number(b), do: a / b
end
<% if true %>
This is correct
<% else %>
This is not
<% end %>
<%= if true %>
This is correct
<% else %>
This is not
<% end %>

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Adam00

Let's go invent tomorrow instead of worrying about what happened yesterday.