LoginSignup
26
21

More than 5 years have passed since last update.

Elixir で Hello world!

Last updated at Posted at 2015-05-15

Elixir とは

  • Erlang VM 上で動作する ruby ライクな関数型言語
  • 作者は rails のコアメンバーの José Valim

Elixir について詳しくはこちらを参照

install Elixir

MacOSX

$ brew install elixir

# if use macports
$ sudo port install elixir

Hello world!!

IEx

ruby の irb のようにインタラクティブで実行する場合は iex コマンドを使用

$ iex
# Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

# Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> IO.puts "Hello world"

# Hello world
# :ok

ファイルから実行

Elixir はコンパイルしてもしなくても実行できる。
コンパイルするファイルは拡張子を .ex にし、
コンパイルせずに実行するファイルは .exs にする慣習らしい。

hello.exs
defmodule Hello do

    def world do
        IO.puts "Hello world"
    end
end

Hello.world
$ elixir hello.exs

# Hello world

コンパイルする場合は elixirc コマンドでファイルを指定する

$ elixirc hello.ex

# Hello world

ファイル自体は Elixir.Hello.beam ってやつが作られるようだ

$ ls

# Elixir.Hello.beam hello.ex hello.exs
26
21
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
21