Elixir Language Hello World


Example

For installation instructions on elixir check here, it describes instructions related to different platforms.

Elixir is a programming language that is created using erlang, and uses erlang's BEAM runtime (like JVM for java).

We can use elixir in two modes: interactive shell iex or directly running using elixir command.

Place the following in a file named hello.exs:

IO.puts "Hello world!"

From the command line, type the following command to execute the Elixir source file:

$ elixir hello.exs

This should output:

Hello world!

This is known as the scripted mode of Elixir. In fact, Elixir programs can also be compiled (and generally, they are) into bytecode for the BEAM virtual machine.

You can also use iex for interactive elixir shell (recommended), run the command you will get a prompt like this:

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>

Here you can try your elixir hello world examples:

iex(1)> IO.puts "hello, world"
hello, world
:ok
iex(2)> 

You can also compile and run your modules through iex. For example, if you have a helloworld.ex that contains:

defmodule Hello do
   def sample do
       IO.puts "Hello World!"
   end
end

Through iex, do:

iex(1)> c("helloworld.ex")
[Hello]
iex(2)> Hello.sample
Hello World!