I’m new to Elixir, and from what I read heavy use of recursion is mandatory. With that in mind, I look at this simple blink example I found:
defmodule FlightController do
use Application
@blink_duration 150 # ms
@led_pin 18
@gpio_on 1
@gpio_off 0
def start(_type, _args) do
{:ok, pid} = Gpio.start_link(@led_pin, :output)
spawn fn -> blink_forever(pid) end
{:ok, self}
end
def blink_forever(pid) do
Gpio.write(pid, @gpio_on)
:timer.sleep @blink_duration
Gpio.write(pid, @gpio_off)
:timer.sleep @blink_duration
blink_forever(pid)
end
end
In my non-Elixir experience, recursive programs build a new stack with each call and release it when the last recursive call returns. You can’t do it forever because you’ll be out of stack space. So, this example couldn’t work on another platform. I have not run it but I’m guessing it does work.
My question, then, is, how does Elixir / BEAM implement recursion?






















