SlideShare a Scribd company logo
1 of 17
Download to read offline
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

What's hot

What's hot (20)

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

Viewers also liked

A moving average analysis of the age distribution and
A moving average analysis of the age distribution andA moving average analysis of the age distribution and
A moving average analysis of the age distribution and
Alexander Decker
 
The Digital Garage Certification
The Digital Garage CertificationThe Digital Garage Certification
The Digital Garage Certification
Stuart Seager
 
September 2010-President's List
September 2010-President's ListSeptember 2010-President's List
September 2010-President's List
Lesley Johnson
 

Viewers also liked (11)

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

Similar to Elixir紹介

02 intro to programming in .net (part 2)
02   intro to programming in .net (part 2)02   intro to programming in .net (part 2)
02 intro to programming in .net (part 2)
Felisha Hosein
 
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
AmanGunner
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
SIVAJISADHANA
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
SIVAJISADHANA
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
SIVAJISADHANA
 
Welcome to the .Net
Welcome to the .NetWelcome to the .Net
Welcome to the .Net
Amr Shawky
 

Similar to Elixir紹介 (20)

20240412 QFM010 Elixir Reading List March 2024
20240412 QFM010 Elixir Reading List March 202420240412 QFM010 Elixir Reading List March 2024
20240412 QFM010 Elixir Reading List March 2024
 
Programing paradigm & implementation
Programing paradigm & implementationPrograming paradigm & implementation
Programing paradigm & implementation
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
 
OOP Comparative Study
OOP Comparative StudyOOP Comparative Study
OOP Comparative Study
 
02 intro to programming in .net (part 2)
02   intro to programming in .net (part 2)02   intro to programming in .net (part 2)
02 intro to programming in .net (part 2)
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and ApproachesBUD17-104: Scripting Languages in IoT: Challenges and Approaches
BUD17-104: Scripting Languages in IoT: Challenges and Approaches
 
Technologies of today
Technologies of todayTechnologies of today
Technologies of today
 
Unit 1
Unit 1Unit 1
Unit 1
 
JAVA
JAVAJAVA
JAVA
 
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzingDEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
DEF CON 23 - Saif el-sherei and etienne stalmans - fuzzing
 
Introduction To Computer Programming
Introduction To Computer ProgrammingIntroduction To Computer Programming
Introduction To Computer Programming
 
Compiler design
Compiler designCompiler design
Compiler design
 
Intro to Elixir talk
Intro to Elixir talkIntro to Elixir talk
Intro to Elixir talk
 
Welcome to the .Net
Welcome to the .NetWelcome to the .Net
Welcome to the .Net
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 

More from Masato HORINOUCHI (6)

Church Numerals
Church NumeralsChurch Numerals
Church Numerals
 
CPS & CTO
CPS & CTOCPS & CTO
CPS & CTO
 
FM synthesis
FM synthesisFM synthesis
FM synthesis
 
Scheme Interpreter in Ruby
Scheme Interpreter in RubyScheme Interpreter in Ruby
Scheme Interpreter in Ruby
 
Clock / Timer
Clock / TimerClock / Timer
Clock / Timer
 
Hash Tree
Hash TreeHash Tree
Hash Tree
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 

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