Submit Search
Upload
ClojurianからみたElixir
•
4 likes
•
2,339 views
Kent Ohashi
Follow
Elixir from a Clojurian's Perspective Clojure使い(Clojurian)としてElixirに入門した話です(*> ᴗ •*)ゞ
Read less
Read more
Software
Report
Share
Report
Share
1 of 55
Download Now
Download to read offline
Recommended
関数型プログラミングのデザインパターンひとめぐり
関数型プログラミングのデザインパターンひとめぐり
Kazuyuki TAKASE
yieldとreturnの話
yieldとreturnの話
bleis tift
Domain Modeling Made Functional (DevTernity 2022)
Domain Modeling Made Functional (DevTernity 2022)
Scott Wlaschin
オブジェクト指向できていますか?
オブジェクト指向できていますか?
Moriharu Ohzu
"Simple Made Easy" Made Easy
"Simple Made Easy" Made Easy
Kent Ohashi
Java ORマッパー選定のポイント #jsug
Java ORマッパー選定のポイント #jsug
Masatoshi Tada
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
JavaからScala、そしてClojureへ: 実務で活きる関数型プログラミング
Kent Ohashi
ソーシャルゲーム案件におけるDB分割のPHP実装
ソーシャルゲーム案件におけるDB分割のPHP実装
infinite_loop
More Related Content
What's hot
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方
Taku Miyakawa
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Scott Wlaschin
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
Masatoshi Tada
Java でつくる低レイテンシ実装の技巧
Java でつくる低レイテンシ実装の技巧
Ryosuke Yamazaki
Everyday Life with clojure.spec
Everyday Life with clojure.spec
Kent Ohashi
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
NTT DATA Technology & Innovation
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門
Ryosuke Uchitate
会社でClojure使ってみて分かったこと
会社でClojure使ってみて分かったこと
Recruit Technologies
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjug
Masatoshi Tada
PostgreSQLの行レベルセキュリティと SpringAOPでマルチテナントの ユーザー間情報漏洩を防止する (JJUG CCC 2021 Spring)
PostgreSQLの行レベルセキュリティと SpringAOPでマルチテナントの ユーザー間情報漏洩を防止する (JJUG CCC 2021 Spring)
Koichiro Matsuoka
アジャイルにモデリングは必要か
アジャイルにモデリングは必要か
Hiromasa Oka
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
yoku0825
C#でわかる こわくないMonad
C#でわかる こわくないMonad
Kouji Matsui
Javaはどのように動くのか~スライドでわかるJVMの仕組み
Javaはどのように動くのか~スライドでわかるJVMの仕組み
Chihiro Ito
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Keiichiro Seida
ADRという考えを取り入れてみて
ADRという考えを取り入れてみて
infinite_loop
今こそ知りたいSpring Web(Spring Fest 2020講演資料)
今こそ知りたいSpring Web(Spring Fest 2020講演資料)
NTT DATA Technology & Innovation
Write Python for Speed
Write Python for Speed
Yung-Yu Chen
今から始める Lens/Prism
今から始める Lens/Prism
Naoki Aoyama
コルーチンでC++でも楽々ゲーム作成!
コルーチンでC++でも楽々ゲーム作成!
amusementcreators
What's hot
(20)
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
Domain Driven Design with the F# type System -- F#unctional Londoners 2014
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
これで怖くない!?コードリーディングで学ぶSpring Security #中央線Meetup
Java でつくる低レイテンシ実装の技巧
Java でつくる低レイテンシ実装の技巧
Everyday Life with clojure.spec
Everyday Life with clojure.spec
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
Form認証で学ぶSpring Security入門
Form認証で学ぶSpring Security入門
会社でClojure使ってみて分かったこと
会社でClojure使ってみて分かったこと
Spring Bootの本当の理解ポイント #jjug
Spring Bootの本当の理解ポイント #jjug
PostgreSQLの行レベルセキュリティと SpringAOPでマルチテナントの ユーザー間情報漏洩を防止する (JJUG CCC 2021 Spring)
PostgreSQLの行レベルセキュリティと SpringAOPでマルチテナントの ユーザー間情報漏洩を防止する (JJUG CCC 2021 Spring)
アジャイルにモデリングは必要か
アジャイルにモデリングは必要か
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
C#でわかる こわくないMonad
C#でわかる こわくないMonad
Javaはどのように動くのか~スライドでわかるJVMの仕組み
Javaはどのように動くのか~スライドでわかるJVMの仕組み
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
Neo4j の「データ操作プログラミング」から 「ビジュアライズ」まで
ADRという考えを取り入れてみて
ADRという考えを取り入れてみて
今こそ知りたいSpring Web(Spring Fest 2020講演資料)
今こそ知りたいSpring Web(Spring Fest 2020講演資料)
Write Python for Speed
Write Python for Speed
今から始める Lens/Prism
今から始める Lens/Prism
コルーチンでC++でも楽々ゲーム作成!
コルーチンでC++でも楽々ゲーム作成!
Similar to ClojurianからみたElixir
Elixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
ClojureScript: The Good Parts
ClojureScript: The Good Parts
Kent Ohashi
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
Michiel Borkent
Introduction to Elixir
Introduction to Elixir
brien_wankel
Clojure Intro
Clojure Intro
thnetos
From Java To Clojure (English version)
From Java To Clojure (English version)
Kent Ohashi
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
Pivorak MeetUp
ECMAScript2015
ECMAScript2015
qmmr
Introducción a Elixir
Introducción a Elixir
Svet Ivantchev
Pune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
PythonOOP
PythonOOP
Veera Pendyala
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Pavlo Baron
Elixir and OTP Apps introduction
Elixir and OTP Apps introduction
Gonzalo Gabriel Jiménez Fuentes
ClojureScript for the web
ClojureScript for the web
Michiel Borkent
Exploring Clojurescript
Exploring Clojurescript
Luke Donnet
Patterns 200711
Patterns 200711
ClarkTony
Coscup2021-rust-toturial
Coscup2021-rust-toturial
Wayne Tsai
Javascript Basics
Javascript Basics
msemenistyi
Clojure 1.1 And Beyond
Clojure 1.1 And Beyond
Mike Fogus
Refactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
Similar to ClojurianからみたElixir
(20)
Elixir @ Paris.rb
Elixir @ Paris.rb
ClojureScript: The Good Parts
ClojureScript: The Good Parts
ClojureScript loves React, DomCode May 26 2015
ClojureScript loves React, DomCode May 26 2015
Introduction to Elixir
Introduction to Elixir
Clojure Intro
Clojure Intro
From Java To Clojure (English version)
From Java To Clojure (English version)
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
ECMAScript2015
ECMAScript2015
Introducción a Elixir
Introducción a Elixir
Pune Clojure Course Outline
Pune Clojure Course Outline
PythonOOP
PythonOOP
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
Elixir and OTP Apps introduction
Elixir and OTP Apps introduction
ClojureScript for the web
ClojureScript for the web
Exploring Clojurescript
Exploring Clojurescript
Patterns 200711
Patterns 200711
Coscup2021-rust-toturial
Coscup2021-rust-toturial
Javascript Basics
Javascript Basics
Clojure 1.1 And Beyond
Clojure 1.1 And Beyond
Refactoring to Macros with Clojure
Refactoring to Macros with Clojure
More from Kent Ohashi
Team Geek Revisited
Team Geek Revisited
Kent Ohashi
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Kent Ohashi
Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界
Kent Ohashi
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
Kent Ohashi
実用のための語源学入門
実用のための語源学入門
Kent Ohashi
メタプログラミング入門
メタプログラミング入門
Kent Ohashi
労働法の世界
労働法の世界
Kent Ohashi
Clojureで作る"simple"なDSL
Clojureで作る"simple"なDSL
Kent Ohashi
RDBでのツリー表現入門
RDBでのツリー表現入門
Kent Ohashi
GraphQL入門
GraphQL入門
Kent Ohashi
たのしい多言語学習
たのしい多言語学習
Kent Ohashi
Ductモジュール入門
Ductモジュール入門
Kent Ohashi
Clojure REPL: The Good Parts
Clojure REPL: The Good Parts
Kent Ohashi
Clojurian Conquest
Clojurian Conquest
Kent Ohashi
GraphQL API in Clojure
GraphQL API in Clojure
Kent Ohashi
法学入門
法学入門
Kent Ohashi
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
Kent Ohashi
Boost your productivity with Clojure REPL
Boost your productivity with Clojure REPL
Kent Ohashi
re-frame à la spec
re-frame à la spec
Kent Ohashi
Clojure Linters
Clojure Linters
Kent Ohashi
More from Kent Ohashi
(20)
Team Geek Revisited
Team Geek Revisited
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Scala vs Clojure?: The Rise and Fall of Functional Languages in Opt Technologies
Clojureコレクションで探るimmutableでpersistentな世界
Clojureコレクションで探るimmutableでpersistentな世界
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
英語学習者のためのフランス語文法入門: フランス語完全理解(?)
実用のための語源学入門
実用のための語源学入門
メタプログラミング入門
メタプログラミング入門
労働法の世界
労働法の世界
Clojureで作る"simple"なDSL
Clojureで作る"simple"なDSL
RDBでのツリー表現入門
RDBでのツリー表現入門
GraphQL入門
GraphQL入門
たのしい多言語学習
たのしい多言語学習
Ductモジュール入門
Ductモジュール入門
Clojure REPL: The Good Parts
Clojure REPL: The Good Parts
Clojurian Conquest
Clojurian Conquest
GraphQL API in Clojure
GraphQL API in Clojure
法学入門
法学入門
Interceptors: Into the Core of Pedestal
Interceptors: Into the Core of Pedestal
Boost your productivity with Clojure REPL
Boost your productivity with Clojure REPL
re-frame à la spec
re-frame à la spec
Clojure Linters
Clojure Linters
Recently uploaded
20140812 - OBD2 Solution
20140812 - OBD2 Solution
Jamie (Taka) Wang
Unlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial Frontiers
Raphaël Semeteys
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
OffsiteNOC
Einstein Copilot Conversational AI for your CRM.pdf
Einstein Copilot Conversational AI for your CRM.pdf
CloudMetic
Revolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM Grid
Mathew Thomas
Technical improvements. Reasons. Methods. Estimations. CJ
Technical improvements. Reasons. Methods. Estimations. CJ
polinaucc
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easy
michealwillson701
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
ICS
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Mind IT Systems
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
BarakaMuyengi
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Inc
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deck
Naval Singh
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
Maxim Salnikov
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
AGATSoftware
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data Mesh
BATbern
Mobile App Development company Houston
Mobile App Development company Houston
jennysmithusa549
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller Resume
Kaylee Miller
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy renewable energy
jeyasrig
Enterprise Content Managements Solutions
Enterprise Content Managements Solutions
IQBG inc
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developers
michealwillson701
Recently uploaded
(20)
20140812 - OBD2 Solution
20140812 - OBD2 Solution
Unlocking AI:Navigating Open Source vs. Commercial Frontiers
Unlocking AI:Navigating Open Source vs. Commercial Frontiers
8 key point on optimizing web hosting services in your business.pdf
8 key point on optimizing web hosting services in your business.pdf
Einstein Copilot Conversational AI for your CRM.pdf
Einstein Copilot Conversational AI for your CRM.pdf
Revolutionize Your Field Service Management with FSM Grid
Revolutionize Your Field Service Management with FSM Grid
Technical improvements. Reasons. Methods. Estimations. CJ
Technical improvements. Reasons. Methods. Estimations. CJ
Boost Efficiency: Sabre API Integration Made Easy
Boost Efficiency: Sabre API Integration Made Easy
Practical Advice for FDA’s 510(k) Requirements.pdf
Practical Advice for FDA’s 510(k) Requirements.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
Flutter the Future of Mobile App Development - 5 Crucial Reasons.pdf
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
CYBER SECURITY AND CYBER CRIME COMPLETE GUIDE.pLptx
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
Splashtop Enterprise Brochure - Remote Computer Access and Remote Support Sof...
VuNet software organisation powerpoint deck
VuNet software organisation powerpoint deck
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
If your code could speak, what would it tell you? Let GitHub Copilot Chat hel...
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BusinessGPT - SECURITY AND GOVERNANCE FOR GENERATIVE AI.pptx
BATbern52 Swisscom's Journey into Data Mesh
BATbern52 Swisscom's Journey into Data Mesh
Mobile App Development company Houston
Mobile App Development company Houston
User Experience Designer | Kaylee Miller Resume
User Experience Designer | Kaylee Miller Resume
renewable energy renewable energy renewable energy renewable energy
renewable energy renewable energy renewable energy renewable energy
Enterprise Content Managements Solutions
Enterprise Content Managements Solutions
Steps to Successfully Hire Ionic Developers
Steps to Successfully Hire Ionic Developers
ClojurianからみたElixir
1.
Clojurian ElixirClojurian Elixir
2.
lagénorhynquelagénorhynque (defprofile lagénorhynque :id @lagenorhynque :reading
"/laʒenɔʁɛ̃k/" :aliases [" "] :languages [Clojure Haskell English français] :interests [programming language-learning law mathematics] :commits ["github.com/lagenorhynque/duct.module.pedestal"] :contributes ["github.com/japan-clojurians/clojure-site-ja"])
3.
6 Lisp6 Lisp
(*> ᴗ •*)(*> ᴗ •*) Clojure : REST API cf. BOOTH https://booth.pm/ja/items/1317263
4.
1. Clojure Elixir 2.
Elixir 3. Clojure 4. Clojure
5.
Clojure ElixirClojure Elixir
6.
ClojureClojure : : 2007 : : Java VM
(JVM) Lisp / Rich Hickey 1.10.0
7.
ElixirElixir : : 2011 : : Erlang VM
(EVM; BEAM) Ruby Clojure José Valim 1.8.2
8.
e.g. 20e.g. 20 ClojureClojure ;;
REPL (read-eval-print loop) user> (->> (iterate (fn [[a b]] [b (+ a b)]) [0 1]) (map first) (take 20)) (0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181)
9.
ElixirElixir # IEx (Interactive
Elixir) iex(1)> Stream.iterate({0, 1}, fn {a, b} -> {b, a+b} end) |> ...(1)> Stream.map(&elem(&1, 0)) |> ...(1)> Enum.take(20) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181] # iex(2)> Stream.unfold({0, 1}, fn {a, b} -> {a, {b, a+b}} end) |> ...(2)> Enum.take(20) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181]
10.
ElixirElixir à la Clojure?
11.
Clojure 2Clojure 2
12.
cf. :cf. :
Programming Clojure, Third EditionProgramming Clojure, Third Edition
13.
ElixirElixir
14.
cf. :cf. :
Programming Elixir ≥ 1.6Programming Elixir ≥ 1.6
15.
Ruby, Io, Prolog,
Scala, Erlang, Clojure, Haskell 7 77 7
16.
Lua, Factor, Elixir,
Elm, Julia, MiniKanren, Idris Seven More Languages in Seven WeeksSeven More Languages in Seven Weeks
17.
Chapter 3, 4,
6: Clojure Chapter 5: Elixir Seven Concurrency Models in Seven WeeksSeven Concurrency Models in Seven Weeks
18.
Mastering Clojure MacrosMastering
Clojure Macros
19.
Metaprogramming ElixirMetaprogramming Elixir
20.
Elixir Erlang/OTPElixir Erlang/OTP ElixirElixir
21.
ElixirElixir ElixirElixir
22.
ElixirElixir Getting StartedGetting
Started
23.
Erlang/Elixir Syntax: A
Crash CourseErlang/Elixir Syntax: A Crash Course
24.
ClojureClojure
27.
ClojureClojure ElixirElixir cf. (Clojure ) user>
'(1 2 3) ; ※ (1 2 3) user> [1 2 3] ; [1 2 3] user> {:a 1 :b 2 :c 3} ; {:a 1, :b 2, :c 3} iex(2)> [1, 2, 3] # [1, 2, 3] iex(3)> {1, 2, 3} # {1, 2, 3} iex(4)> %{a: 1, b: 2, c: 3} # %{a: 1, b: 2, c: 3}
28.
// ClojureClojure ElixirElixir user> (ns example)
; `example` nil example> (defn square [x] ; `square` (* x x)) #'example/square example> (in-ns 'user) ; `user` #namespace[user] user> iex(5)> defmodule Example do # `Example` ...(5)> def square(x) do # `square` ...(5)> x * x ...(5)> end ...(5)> end {:module, Example, <<70, 79, 82, 49, 0, 0, 4, 100, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 14, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, {:square, 1}}
29.
ClojureClojure ElixirElixir user> (example/square 3)
; `example` `square` 9 user> (map example/square (range 1 (inc 10))) (1 4 9 16 25 36 49 64 81 100) iex(6)> Example.square(3) # `Example` `square` 9 iex(7)> Enum.map(1..10, &Example.square/1) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
30.
// ClojureClojure ElixirElixir user> (map (fn
[x] (* x x)) (range 1 (inc 10))) (1 4 9 16 25 36 49 64 81 100) user> (map #(* % %) (range 1 (inc 10))) (1 4 9 16 25 36 49 64 81 100) iex(8)> Enum.map(1..10, fn(x) -> x * x end) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] iex(8)> Enum.map(1..10, &(&1 * &1)) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
31.
>>>> (threading macro)
vs(threading macro) vs |>|> (pipe operator)(pipe operator) ClojureClojure ElixirElixir cf. user> (->> (range 1 (inc 10)) (map #(* % %)) (filter odd?) (apply +)) 165 iex(9)> require Integer Integer iex(10)> 1..10 |> ...(10)> Enum.map(&(&1 * &1)) |> ...(10)> Enum.filter(&Integer.is_odd/1) |> ...(10)> Enum.sum 165
33.
ClojureClojure ElixirElixir user> (defprotocol Shape
; `Shape` (area [x])) ; `area` Shape iex(1)> defprotocol Shape do # `Shape` ...(1)> def area(x) # `area` ...(1)> end {:module, Shape, ..., {:__protocol__, 1}}
34.
// ClojureClojure user> (defrecord Triangle
[x h] ; `Triangle` Shape ; (area [{:keys [x h]}] (/ (* x h) 2))) user.Triangle user> (area (map->Triangle {:x 3 :h 2})) 3 user> (defrecord Rectangle [x y] ; `Rectangle` Shape ; (area [{:keys [x y]}] (* x y))) user.Rectangle user> (area (map->Rectangle {:x 2 :y 3})) 6
35.
ElixirElixir iex(2)> defmodule Triangle
do # `Triangle` ...(2)> defstruct [:x, :h] ...(2)> end {:module, Triangle, ..., %Triangle{h: nil, x: nil}} iex(3)> defimpl Shape, for: Triangle do # ...(3)> def area(%Triangle{x: x, h: h}), do: x * h / 2 ...(3)> end {:module, Shape.Triangle, ..., {:__impl__, 1}} iex(4)> Shape.area(%Triangle{x: 3, h: 2}) 3.0 iex(5)> defmodule Rectangle do # `Rectangle` ...(5)> defstruct [:x, :y] ...(5)> end {:module, Rectangle, ..., %Rectangle{x: nil, y: nil}} iex(6)> defimpl Shape, for: Rectangle do # ...(6)> def area(%Rectangle{x: x, y: y}), do: x * y ...(6)> end {:module, Shape.Rectangle, ..., {:__impl__, 1}} iex(7)> Shape.area(%Rectangle{x: 2, y: 3}) 6
36.
ClojureClojure ElixirElixir user> (defrecord Circle
[r]) ; `Circle` user.Circle user> (area (map->Circle {:r 3})) Execution error (IllegalArgumentException) at user/eval5412$fn$G (REPL:47). No implementation of method: :area of protocol: #'user/Shape fou nd for class: user.Circle iex(8)> defmodule Circle do # `Circle` ...(8)> defstruct [:r] ...(8)> end {:module, Circle, ..., %Circle{r: nil}} iex(9)> Shape.area(%Circle{r: 3}) ** (Protocol.UndefinedError) protocol Shape not implemented for %Circle{r: 3} iex:2: Shape.impl_for!/1 iex:3: Shape.area/1
37.
ClojureClojure ElixirElixir user> (extend-protocol Shape
; Circle (area [{:keys [r]}] (* Math/PI r r))) nil user> (area (map->Circle {:r 3})) 28.274333882308138 iex(10)> defimpl Shape, for: Circle do # ...(10)> def area(%Circle{r: r}), do: :math.pi() * r * r ...(10)> end {:module, Shape.Circle, ..., {:__impl__, 1}} iex(11)> Shape.area(%Circle{r: 3}) 28.274333882308138
39.
ASTAST ClojureClojure user> '(when (=
1 1) (println "Truthy!")) (when (= 1 1) (println "Truthy!")) ;; user> (quote (when (= 1 1) (println "Truthy!"))) (when (= 1 1) (println "Truthy!"))
40.
ElixirElixir iex(1)> quote do ...(1)>
if 1 == 1 do ...(1)> IO.puts "Truthy!" ...(1)> end ...(1)> end {:if, [context: Elixir, import: Kernel], [ {:==, [context: Elixir, import: Kernel], [1, 1]}, [ do: {{:., [], [{:__aliases__, [alias: false], [:IO]}, :puts ]}, [], ["Truthy!"]} ] ]}
41.
ClojureClojure user> (ns example) nil example>
(defmacro my-when-not [test & body] `(if ~test nil (do ~@body))) #'example/my-when-not example> (in-ns 'user) #namespace[user] user>
42.
ElixirElixir iex(2)> defmodule Example
do ...(2)> defmacro my_unless(test, do: body) do ...(2)> quote do ...(2)> if unquote(test), do: nil, else: unquote(body) ...(2)> end ...(2)> end ...(2)> end {:module, Example, ..., {:my_unless, 2}}
43.
ClojureClojure user> (example/my-when-not (=
1 2) (println "Falsy!") 42) Falsy! 42 user> (example/my-when-not (= 1 1) (println "Falsy!") 42) nil
44.
ElixirElixir iex(3)> require Example Example iex(4)>
Example.my_unless 1 == 2 do ...(4)> IO.puts "Falsy!" ...(4)> 42 ...(4)> end Falsy! 42 iex(5)> Example.my_unless 1 == 1 do ...(5)> IO.puts "Falsy!" ...(5)> 42 ...(5)> end nil
45.
ClojureClojure user> (macroexpand-1 ;
1 '(example/my-when-not (= 1 2) (println "Falsy!") 42)) (if (= 1 2) nil (do (println "Falsy!") 42))
46.
ElixirElixir iex(6)> quote do ...(6)>
Example.my_unless 1 == 2 do ...(6)> IO.puts "Falsy!" ...(6)> 42 ...(6)> end ...(6)> end |> Macro.expand_once(__ENV__) |> # 1 ...(6)> Macro.to_string |> IO.puts # AST if(1 == 2) do nil else IO.puts("Falsy!") 42 end :ok
47.
ClojureClojure
48.
vs cf. (by Rich
Hickey) REPL cf. REPL (REPL-driven development) Simple Made Easy
49.
Elixirists Clojurians (?)Elixirists
Clojurians (?)
50.
Further ReadingFurther Reading
51.
: : https://clojure.org https://japan- clojurians.github.io/clojure-site-ja/ https://elixir-lang.org https://elixir-lang.jp Getting Started Erlang/Elixir Syntax:
A Crash Course
52.
: : Clojure 2 Programming Clojure,
Third Edition Elixir Programming Elixir ≥ 1.6 7 7 Seven More Languages in Seven Weeks
53.
Seven Concurrency Models
in Seven Weeks Scala/Akka (Chapter 5) Mastering Clojure Macros Metaprogramming Elixir
54.
Elixir Erlang/OTP Elixir Elixir Elixir
55.
: https://scrapbox.io/lagenorhynque/Elixir lagenorhynque/programming-elixir
Download Now