How to run an Elixir application?

mix run does run your app. It’s just that when you simply put IO.puts “something” in a file that line is only evaluated in compile-time, it does nothing at runtime. If you want something to get started when you start your app you need to specify that in your mix.exs. Usually you want a top-level … Read more

Elixir: When to use .ex and when .exs files

.ex is for compiled code, .exs is for interpreted code. ExUnit tests, for example, are in .exs files so that you don’t have to recompile every time you make a change to your tests. If you’re writing scripts or tests, use .exs files. Otherwise, just use .ex files and compile your code. As far as … Read more

What is the benefit of Keyword Lists?

Keyword List Map/Struct HashDict (deprecated) Duplicate keys yes no no Ordered yes no no Pattern matching yes  yes no Performance¹ (Insert) very fast² fast³ fast⁴ Performance¹ (Access) slow⁵ fast³ fast⁴ Keyword lists are lightweight and have a simple structure underneath them, which makes them very flexible. You can think of them as syntax sugar on … Read more

Elixir: use vs import

import Module brings all the Functions and Macros of Module un-namespaced into your module. require Module allows you to use macros of Module but does not import them. (Functions of Module are always available namespaced.) use Module first requires module and then calls the __using__ macro on Module. Consider the following: defmodule ModA do defmacro … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)