Hello Elixir ❤️

How do you write "Hello, world!" in Elixir?

In the Elixir programming language, you can write a "Hello, world!" program using the following code:

IO.puts("Hello, world!")
iex>  

Explanation

  • Elixir doesn't need "boilerplate" for simple programs!
  • Elixir strings (text) use double quotes: "Hello, world!"
  • We use the IO.puts/1 function to print to the console.
  • In Elixir, /1 in IO.puts/1 means that the function takes one argument
  • The IO module in Elixir provides functions for reading from and writing to the standard input/output.

How do you run the "Hello, world" code in Elixir?

There are a few options for running Elixir code! The quickest option is to use the IEx REPL, an Elixir command line. You start it by typing iex in your terminal:

$iex

Now you should get an IEx shell with the iex> prompt:

iex>  

Now enter the code:

iex>  IO.puts("Hello, world!")

You'll notice that there's an:ok at the end. This is the return value of the function.

All Elixir functions have return values, and:ok means the function succeeded.