← Code Compare

Hello, World

The classic first program: print the line Hello, BEAM!. Notice how the BEAM languages diverge already on day one - Erlang and LFE reach for io:format, Elixir has a friendly IO.puts, Gleam routes everything through its typed gleam/io module, and Luerl runs plain Lua's print. Watch the surface syntax (S-expressions vs. pipes vs. ML-style) while the underlying runtime stays the same.

Show: ErlangElixirGleamLFELuerl
Erlang
-module(hello).
-export([main/0]).

main() ->
    io:format("Hello, BEAM!~n").

Erlang wraps code in a -module/-export pair and prints with io:format/1, where ~n is the format control sequence for a newline.

Elixir
defmodule Hello do
  def main do
    IO.puts("Hello, BEAM!")
  end
end

Hello.main()

Elixir's IO.puts/1 writes a string and appends the newline for you; modules and functions are defined with defmodule and def.

Gleam
import gleam/io

pub fn main() -> Nil {
  io.println("Hello, BEAM!")
}

Gleam keeps side effects explicit: you import gleam/io and call io.println, which returns Nil - the empty type that the public main function also yields.

LFE
(defmodule hello
  (export (main 0)))

(defun main ()
  (io:format "Hello, BEAM!~n"))

Lisp Flavoured Erlang expresses the same module in S-expressions, calling the very same io:format BEAM function with Erlang's ~n newline directive.

Luerl
local function main()
  print("Hello, BEAM!")
end

main()

Luerl runs standard Lua on the BEAM, so the idiomatic choice is Lua's built-in print, which writes its arguments followed by a newline.