Elixir紹介
2014/05/08
SICP Club LT
Livesense Inc.
HORINOUCHI Masato
Elixirとは
Elixir is a func-onal, meta-programming aware language built on
top of the Erlang VM. It is a dynamic language that focuses on
tooling to leverage Erlang's abili-es to build concurrent, distributed
and fault-tolerant applica-ons with hot code upgrades.
見た目は
Ruby
中身は
Lisp
特徴
• 近代的なシンタックス
• 全てが式
• 強力なメタプログラミング機能
• 第一級オブジェクトとしてのドキュメント
• Erlangランタイムとの相互運用
Fibonacci (Ruby)
class Fib
def self.fib n
case n
when 0 then 0
when 1 then 1
else fib(n - 1) + fib(n - 2)
end
end
end
puts Fib.fib 10
Fibonacci (Elixir)
defmodule Fib do
def fib(0), do: 1
def fib(1), do: 1
def fib(n), do: fib(n-1) + fib(n-2)
end
IO.puts Fib.fib 6
Install
• OS X (homebrew)
• $ brew install erlang –devel
• $ brew install elixir
• Windows
• なんか大変らしい
• Ubuntu
• PPA あるよ
REPL
$ iex
iex> defmodule Hello do
...> def world do
...> IO.puts "Hello, world"
...> end
...> end
iex> Hello.world
Hello, world
:ok
iex>
無名関数
iex> f = fn(x) -> x * 2 end
iex> f.(4)
8
iex> (fn(x) -> x * 3 end).(3)
9
map reduce
iex> Enum.map(
...> [1,2,3],
...> fn(x) -> x * 2 end)
[2, 4, 6]
iex> Enum.reduce(
...> [1,2,3],
...> fn(x, acc) -> x + acc end)
6
キーワード引数と括弧の省略
iex> if true do
...> 1
...> else
...> 2
...> end
1
iex> if true, do: 1, else: 2
1
iex> if true, [do: 1, else: 2]
1
iex> if(true, [do: 1, else: 2])
1
Homoiconicity
In a homoiconic language the primary representa3on of programs is
also a data structure in a primi3ve type of the language itself. This
makes metaprogramming easier than in a language without this
property, since code can be treated as data: reflec3on in the
language (examining the program's en33es at run3me) depends on
a single, homogeneous structure, and it does not have to handle
several different structures that would appear in a complex syntax.
To put that another way, homoiconicity is where a program's source
code is wriDen as a basic data structure that the programming
language knows how to access.
quote
iex> length [1,2,3]
3
iex> quote do: length [1,2,3]
{:length, [context: Elixir, import: Kernel], [[1, 2, 3]]}
iex> 1 + 2
3
iex> quote do: 1 + 2
{:+, [context: Elixir, import: Kernel], [1, 2]}
macro
iex> defmodule MyUnless do
...> defmacro unless(clause, options) do
...> quote do: if !unquote(clause),
...> unquote(options)
...> end
...> end
iex> require MyUnless
nil
Iex> MyUnless.unless true, do: 1, else: 2
2
defmacro if
defmacro if(condition, clauses) do
do_clause = Keyword.get(clauses, :do, nil)
else_clause = Keyword.get(clauses, :else, nil)
quote do
case unquote(condition) do
_ in [false, nil] -> unquote(else_clause)
_ -> unquote(do_clause)
end
end
end
if すらもマクロ
ご清聴ありがとうございました

More Related Content

PPTX
Protocol Buffer.ppt
PPTX
Reversing Google Protobuf protocol
PPTX
Protocol buffers
PDF
Elixir & Phoenix 推坑
PPT
Building scalable and language-independent Java services using Apache Thrift ...
PPTX
Dynamic language
PDF
How to Learn Java Programming
PPTX
Concurrency & Parallel Programming
Protocol Buffer.ppt
Reversing Google Protobuf protocol
Protocol buffers
Elixir & Phoenix 推坑
Building scalable and language-independent Java services using Apache Thrift ...
Dynamic language
How to Learn Java Programming
Concurrency & Parallel Programming

What's hot (20)

PPTX
Textual programming in key stage 3
PPTX
VB.NET:An introduction to Namespaces in .NET framework
PDF
LIL Presentation
PPTX
Python - Lesson 1
PDF
web programming UNIT VIII python by Bhavsingh Maloth
PDF
Create Your Own Language
PPTX
Before Starting Python Programming Language
DOCX
.Net framework components by naveen kumar veligeti
PPTX
Python Tutorial for Beginner
PPTX
Programming
PDF
Elixir's Object Oriented Layer
PDF
Introduction To Python | Edureka
PPTX
Presentation of Python, Django, DockerStack
PPTX
Introduction about Python by JanBask Training
PDF
Socket Programming In Python
PDF
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
PPTX
GDG Helwan Introduction to python
PDF
Erlang - Concurrent Language for Concurrent World
PDF
Pharo foreign function interface (FFI) by example by Esteban Lorenzano
PPTX
Python final presentation kirti ppt1
Textual programming in key stage 3
VB.NET:An introduction to Namespaces in .NET framework
LIL Presentation
Python - Lesson 1
web programming UNIT VIII python by Bhavsingh Maloth
Create Your Own Language
Before Starting Python Programming Language
.Net framework components by naveen kumar veligeti
Python Tutorial for Beginner
Programming
Elixir's Object Oriented Layer
Introduction To Python | Edureka
Presentation of Python, Django, DockerStack
Introduction about Python by JanBask Training
Socket Programming In Python
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
GDG Helwan Introduction to python
Erlang - Concurrent Language for Concurrent World
Pharo foreign function interface (FFI) by example by Esteban Lorenzano
Python final presentation kirti ppt1
Ad

Viewers also liked (11)

PDF
A mathematical appraisal
PDF
A moving average analysis of the age distribution and
DOC
Gresume0716
PDF
أخطاء و ضلالات سيد قطب بالكتاب والصفحة و رد العلماء عليه
PPTX
Who’d be a parent - your role in drug and alcohol prevention
PDF
Inside mml2wav.rb
PDF
The Digital Garage Certification
PDF
POSIX Threads
PDF
September 2010-President's List
PPTX
学生、教職員が一線に並んで交流できる 「英語でビブリオバトル」
A mathematical appraisal
A moving average analysis of the age distribution and
Gresume0716
أخطاء و ضلالات سيد قطب بالكتاب والصفحة و رد العلماء عليه
Who’d be a parent - your role in drug and alcohol prevention
Inside mml2wav.rb
The Digital Garage Certification
POSIX Threads
September 2010-President's List
学生、教職員が一線に並んで交流できる 「英語でビブリオバトル」
Ad

Similar to Elixir紹介 (20)

PDF
20240412 QFM010 Elixir Reading List March 2024
PDF
Programing paradigm & implementation
PDF
Seeking Clojure
PDF
OOP Comparative Study
PPTX
02 intro to programming in .net (part 2)
PDF
Intro to programming and intro to java netbean.pdf
PPTX
Lecture 1 introduction to language processors
PDF
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
PPT
Technologies of today
PPTX
Introduction to computer and its fundamentals.pptx
DOCX
DOCX
Unit 1
PPT
lect1-introductiontoprogramminglanguages-130130013038-phpapp02.ppt
DOC
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
DOCX
New microsoft office word document
DOCX
New microsoft office word document
DOCX
New microsoft office word document
PDF
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
PPTX
Introduction To Computer Programming
PDF
Compiler design
20240412 QFM010 Elixir Reading List March 2024
Programing paradigm & implementation
Seeking Clojure
OOP Comparative Study
02 intro to programming in .net (part 2)
Intro to programming and intro to java netbean.pdf
Lecture 1 introduction to language processors
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
Technologies of today
Introduction to computer and its fundamentals.pptx
Unit 1
lect1-introductiontoprogramminglanguages-130130013038-phpapp02.ppt
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
New microsoft office word document
New microsoft office word document
New microsoft office word document
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
Introduction To Computer Programming
Compiler design

More from Masato HORINOUCHI (6)

PDF
Church Numerals
PDF
PDF
FM synthesis
PDF
Scheme Interpreter in Ruby
PDF
Clock / Timer
PDF
Church Numerals
FM synthesis
Scheme Interpreter in Ruby
Clock / Timer

Recently uploaded (20)

PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPT
What is a Computer? Input Devices /output devices
PPTX
2018-HIPAA-Renewal-Training for executives
PDF
CloudStack 4.21: First Look Webinar slides
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PDF
Developing a website for English-speaking practice to English as a foreign la...
PDF
Getting started with AI Agents and Multi-Agent Systems
PPTX
Chapter 5: Probability Theory and Statistics
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Five Habits of High-Impact Board Members
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PPTX
Modernising the Digital Integration Hub
PDF
Improvisation in detection of pomegranate leaf disease using transfer learni...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
What is a Computer? Input Devices /output devices
2018-HIPAA-Renewal-Training for executives
CloudStack 4.21: First Look Webinar slides
Custom Battery Pack Design Considerations for Performance and Safety
sustainability-14-14877-v2.pddhzftheheeeee
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Developing a website for English-speaking practice to English as a foreign la...
Getting started with AI Agents and Multi-Agent Systems
Chapter 5: Probability Theory and Statistics
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Five Habits of High-Impact Board Members
A review of recent deep learning applications in wood surface defect identifi...
Flame analysis and combustion estimation using large language and vision assi...
A proposed approach for plagiarism detection in Myanmar Unicode text
Convolutional neural network based encoder-decoder for efficient real-time ob...
Modernising the Digital Integration Hub
Improvisation in detection of pomegranate leaf disease using transfer learni...
Final SEM Unit 1 for mit wpu at pune .pptx
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx

Elixir紹介

  • 2. Elixirとは Elixir is a func-onal, meta-programming aware language built on top of the Erlang VM. It is a dynamic language that focuses on tooling to leverage Erlang's abili-es to build concurrent, distributed and fault-tolerant applica-ons with hot code upgrades.
  • 4. 特徴 • 近代的なシンタックス • 全てが式 • 強力なメタプログラミング機能 • 第一級オブジェクトとしてのドキュメント • Erlangランタイムとの相互運用
  • 5. Fibonacci (Ruby) class Fib def self.fib n case n when 0 then 0 when 1 then 1 else fib(n - 1) + fib(n - 2) end end end puts Fib.fib 10
  • 6. Fibonacci (Elixir) defmodule Fib do def fib(0), do: 1 def fib(1), do: 1 def fib(n), do: fib(n-1) + fib(n-2) end IO.puts Fib.fib 6
  • 7. Install • OS X (homebrew) • $ brew install erlang –devel • $ brew install elixir • Windows • なんか大変らしい • Ubuntu • PPA あるよ
  • 8. REPL $ iex iex> defmodule Hello do ...> def world do ...> IO.puts "Hello, world" ...> end ...> end iex> Hello.world Hello, world :ok iex>
  • 9. 無名関数 iex> f = fn(x) -> x * 2 end iex> f.(4) 8 iex> (fn(x) -> x * 3 end).(3) 9
  • 10. map reduce iex> Enum.map( ...> [1,2,3], ...> fn(x) -> x * 2 end) [2, 4, 6] iex> Enum.reduce( ...> [1,2,3], ...> fn(x, acc) -> x + acc end) 6
  • 11. キーワード引数と括弧の省略 iex> if true do ...> 1 ...> else ...> 2 ...> end 1 iex> if true, do: 1, else: 2 1 iex> if true, [do: 1, else: 2] 1 iex> if(true, [do: 1, else: 2]) 1
  • 12. Homoiconicity In a homoiconic language the primary representa3on of programs is also a data structure in a primi3ve type of the language itself. This makes metaprogramming easier than in a language without this property, since code can be treated as data: reflec3on in the language (examining the program's en33es at run3me) depends on a single, homogeneous structure, and it does not have to handle several different structures that would appear in a complex syntax. To put that another way, homoiconicity is where a program's source code is wriDen as a basic data structure that the programming language knows how to access.
  • 13. quote iex> length [1,2,3] 3 iex> quote do: length [1,2,3] {:length, [context: Elixir, import: Kernel], [[1, 2, 3]]} iex> 1 + 2 3 iex> quote do: 1 + 2 {:+, [context: Elixir, import: Kernel], [1, 2]}
  • 14. macro iex> defmodule MyUnless do ...> defmacro unless(clause, options) do ...> quote do: if !unquote(clause), ...> unquote(options) ...> end ...> end iex> require MyUnless nil Iex> MyUnless.unless true, do: 1, else: 2 2
  • 15. defmacro if defmacro if(condition, clauses) do do_clause = Keyword.get(clauses, :do, nil) else_clause = Keyword.get(clauses, :else, nil) quote do case unquote(condition) do _ in [false, nil] -> unquote(else_clause) _ -> unquote(do_clause) end end end