Erlang Processes vs Java Threads

Repeat after me: “These are different paradigms” Say that aloud 20 times or so — it is our mantra for the moment. If we really must compare apples and oranges, let’s at least consider where the common aspects of “being fruit” intersect. Java “objects” are a Java programmer’s basic unit of computation. That is, an … Read more

How can I schedule code to run every few hours in Elixir or Phoenix framework?

There is a simple alternative that does not require any external dependencies: defmodule MyApp.Periodically do use GenServer def start_link(_opts) do GenServer.start_link(__MODULE__, %{}) end def init(state) do schedule_work() # Schedule work to be performed at some point {:ok, state} end def handle_info(:work, state) do # Do the work you desire here schedule_work() # Reschedule once more … Read more

Are Elixir variables really immutable?

Don’t think of “variables” in Elixir as variables in imperative languages, “spaces for values”. Rather look at them as “labels for values”. Maybe you would better understand it when you look at how variables (“labels”) work in Erlang. Whenever you bind a “label” to a value, it remains bound to it forever (scope rules apply … Read more

Integer List printed as String in Elixir

The value you see ‘efgh’ is not a String but a Charlist. The result of your statement should be [101, 102, 103, 104] (and it actually is), but it doesn’t output it that way. The four values in your list map to e, f, g and h in ASCII, so iex just prints their codepoints … Read more

Elixir lists interpreted as char lists

Elixir has two kinds of strings: binaries (double quoted) and character lists (single quoted). The latter variant is inherited from Erlang and is internally represented as a list of integers, which map to the codepoints of the string. When you use functions like inspect and IO.inspect, Elixir tries to be smart and format a list … Read more