SlideShare a Scribd company logo
1 of 80
Download to read offline
Egison Pattern Matching 
in Ruby 
- Express Intuition Directly with 
Essentially New Syntax - 
Vol.01 Sep/18/2014 
Satoshi Egi 
Rakuten Institute of Technology 
http://rit.rakuten.co.jp/
2 
Self-Introduction 
Name 
Satoshi Egi (江木 聡志) 
Association 
Rakuten Institute of Technology (楽天技術研究所) 
Education 
Majored Computer Science in the University of 
Tokyo 
Interests 
Programming Languages, AI (Mathematics) 
Website 
http://www.egison.org/~egi/
3 
Very Quick Introduction of Today’s Contents 
I have created the programming language that 
realized non-linear pattern-matching even 
against data that have no standard form. 
Non-linear patterns allow multiple occurrences of same variables 
in a pattern 
Enumerate the elements of 
the collection ‘xs’ that appear 
more than twice 
(match-all xs (multiset integer)! 
[<cons $x <cons ,x _>> x])! 
Egison 
pairs = []! 
(1..n).each do |i|! 
(i..n).each do |j|! 
if xs[i] == xs[j]! 
pairs = pairs +! 
xs[i]! 
end! 
end! 
end! 
Ruby
4 
Very Quick Introduction of Today’s Contents 
I have implemented the same feature in Ruby! 
The source code on GitHub! 
https://github.com/egison/egison-ruby 
Enumerate the elements of 
the collection ‘xs’ that appear 
more than twice 
match_all(xs) do! 
with(Multiset.(_x,__x, *_)) { x }! 
end! 
Ruby with Egison gem 
pairs = []! 
(1..n).each do |i|! 
(i..n).each do |j|! 
if xs[i] == xs[j]! 
pairs = pairs +! 
xs[i]! 
end! 
end! 
end! 
Ruby
5 
Very Quick Introduction of Today’s Contents 
Poker hands analyzer with a single expression in Ruby! 
Our pattern-matching expression 
represents all hands in a single pattern
6 
Very Quick Introduction of Today’s Contents 
We can also pattern-match against infinite streams. 
… , x, x + 2, …
7 
Source and English Document are on GitHub 
https://github.com/egison/egison-ruby
8 
Please Check My Blog Article, too
9 
We wrote also Japanese Documents on Qiita 
1,0004 views, 185 Hatena Bookmarks!
10 
Table of Contents 
1. Introduction - What is Pattern Matching? 
2. Egison Pattern Matching in Ruby 
3. Let’s Try Egison Gem 
4. Future Goal – Application of Egison
11 
Table of Contents 
1. Introduction - What is Pattern Matching? 
2. Egison Pattern Matching in Ruby 
3. Let’s Try Egison Gem 
4. Future Goal – Application of Egison
12 
What is Pattern Matching? 
A feature of programming languages that 
simplifies programs. 
• Data Decomposition 
• Pattern-matching enables us to extract and 
examine the value of an instance variable very 
easily 
• Conditional Branches 
• Pattern-matching eliminates nested and 
complex conditional branches
13 
Greeting Demonstration
14 
Greeting Demonstration
15 
Greeting Demonstration
16 
Greeting Demonstration 
fail
17 
Greeting Demonstration 
success
18 
Greeting Demonstration
19 
Flow of Pattern Matching 
fail
20 
Flow of Pattern Matching 
success
21 
Greeting Demonstration
22 
Flow of Pattern Matching 
fail
23 
Flow of Pattern Matching 
fail
24 
Flow of Pattern Matching 
fail
25 
Flow of Pattern Matching 
fail
26 
Flow of Pattern Matching 
success
27 
Greeting Demonstration
28 
Table of Contents 
1. Introduction - What is Pattern Matching? 
2. Egison Pattern Matching in Ruby 
3. Let’s Try Egison Gem 
4. Future Goal – Application of Egison
29 
The Features of Egison Pattern-Matching in Ruby 
We have features in addition to simplification of 
data decomposition and conditional branches 
• Customizable Way of Pattern-Matching 
• We can do pattern-matching against not only 
fixed data such as lists but also multisets and 
sets that have multiple ways of decomposition 
• Non-Linear Pattern-Matching 
• We allow multiple occurrences of same 
variables in patterns 
• Pattern-Matching with Backtracking 
• We allow multiple results of pattern-matching 
even infinite results
30 
Customizable Pattern Matching For Various Data 
We can define how to pattern-match for each data 
types
31 
Pattern Matching with Multiple Results 
We can handle multiple results of pattern-matching
32 
Element Patterns and Collection Patterns 
A literal that starts with ‘_’ is a pattern-variable. We 
can refer the result of pattern-matching through 
them.
33 
Element Patterns and Collection Patterns 
A subcollection pattern matches the subcollection 
of the target array. A subcollection pattern starts 
with ‘*’.
34 
Element Patterns and Collection Patterns 
A literal that starts with ‘_’ is a pattern-variable. We 
can refer the result of pattern-matching through 
them.
35 
Element Patterns and Collection Patterns 
A subcollection pattern matches the subcollection 
of the target array. A subcollection pattern starts 
with ‘*’.
36 
Combinations with Pattern Matching 
… , x, …, y, … 
… , x, …, y, …, z, …
37 
Non-Linear Pattern Matching 
A Pattern whose form is ‘__("...")’ is a value pattern
38 
Non-Linear Pattern Matching 
A Pattern whose form is ‘__("...")’ is a value pattern 
We can omit (“ and “) when enclosed 
with them is a single variable
39 
Poker Hands Analyzer in Ruby
40 
The Pattern for Straight Flash 
Pattern for straight flash
41 
The Pattern for Straight Flash 
Pattern for straight flash
42 
Poker Hands Analyzer in Ruby 
Same suit with $s
Numbers are serial from $n 
43 
Poker Hands Analyzer in Ruby 
Same suit with $s 
We can write any expression after ‘__’
44 
Poker Hands Analyzer in Ruby 
Pattern for two pairs
45 
The Pattern for Two Pairs 
Pattern for two pairs
46 
The Pattern for Two Pairs 
Pattern for two pairs 
Same number with $m 
Same number with $n
47 
The Pattern for Two Pairs 
Pattern for two pairs 
Same number with $m 
Same number with $n 
Non-linear patterns have very strong power
48 
Poker Hands Analyzer in Ruby 
Non-linear patterns enables to 
represent all hands in a single pattern
Pattern Matching against Streams with Infinite Results 
We can also pattern-match against infinite streams. 
49 
… , x, x + 2, …
50 
One More Interesting Demonstration 
We can also enumerate prime triplets using and-patterns 
and or-patterns effectively.
51 
Table of Contents 
1. Introduction - What is Pattern Matching? 
2. Egison Pattern Matching in Ruby 
3. Let’s Try Egison Gem 
4. Future Goal – Application of Egison
52 
Egison Gem is on GitHub 
https://github.com/egison/egison-ruby
53 
Try Egison Gem! 
Egison Gem is written in pure Ruby. 
Installation is very easy via RubyGems. 
$ git clone https://github.com/egison/egison-ruby.git 
$ cd egison-ruby/ 
$ bundle install 
$ make 
$ ls sample/ 
… sample/poker_hands.rb … 
$ ruby sample/poker_hands.rb 
… 
We have prepared a lot of samples. 
Please try all of them.
54 
Table of Contents 
1. Introduction - What is Pattern Matching? 
2. Egison Pattern Matching in Ruby 
3. Let’s Try Egison Gem 
4. Future Goal – Application of Egison
55 
Introduction of the Egison Programming Language
56 
Profile of Egison 
I have created Egison to represent human’s intuition 
directly. 
Paradigm 
Pattern-matching-oriented, 
Purely functional 
Author 
Satoshi Egi 
License 
MIT 
Version 
3.3.12 (2014/9/18) 
First Released 
2011/5/24 
Filename Extension 
.egi 
Implemented in 
Haskell (about 3,500 lines)
57 
The Additional Features of Pure Egison 
We have features in additon to simplification of 
data decomposition and conditional branches 
• Ways of Pattern-Matching is More Customizable 
• We can customize the way of pattern-matching 
against not only against collection 
such as lists, multisets and sets 
• Pattern Modularization with Lexical Scoping 
• We allow multiple occurrences of same 
variables in patterns
58 
More complex example, Mahjong
59 
More complex example, Mahjong 
Two same tiles 
Three consecutive tiles 
Three same tiles
60 
More complex example, Mahjong 
Two same tiles 
Three consecutive tiles 
Three same tiles 
Seven twins or one twin + four shuntsu or kohtsu
61 
More complex example, Mahjong 
Two same tiles 
Three consecutive tiles 
Three same tiles 
Seven twins or one twin + four shuntsu or kohtsu 
Pattern modularization makes 
programming more simple!
62 
Egison on an online media
63 
Egison on Hacker News 
Egison was actively discussed 
on Hacker News twice!
64 
Access Map of the Website in This Half Year 
(2014/1/14 – 2014/7/14) 
Total session is 14,109
65 
Egison will be taught in the University of Tokyo by 
Prof. Hagiya 
Egison will have big impact on 
the academic world, too!
66 
Growth of Community in This Year (2013/11/15 – 2014/9/18) 
• Mailing List Members 
• Before: 12 – Only my friends 
• Current: 23 – Communicating in English 
• Stargazers on GitHub 
• Before: 12 – Only my friends 
• Current: 214 – People from all over the world!
67 
My Mind Map on Programming Language
68 
My Mind Map on Programming Language
69 
My Mind Map on Programming Language 
Egison is pioneering this field!
70 
Application of Egison
71 
There is a Wide Range of Application 
• Daily programming 
• Able to express complex tasks simply 
• Data access and analysis 
• Work as the most elegant query language 
• Able to access the wide range of data types in a 
unified way 
• Natural language processing 
• Able to handle complex structures intuitively as 
humans do in their mind 
• AI (Mathematical expression handling) 
• Able to handle various mathematical and abstract 
notions directly
72 
Query example 
• Query that returns twitter users who are 
followed by “__Egi” but not follow back 
“__Egi”. 
User: 
id integer 
name string 
Follow: 
from_id integer 
to_id Integer
73 
SQL version 
• Complex and difficult to understand 
• Complex where clause contains “NOT EXIST” 
• Subquery
74 
Egison version 
• Very Simple 
• No where clauses 
• No subquery
75 
Egison version 
• Very Simple 
• No where clauses 
• No subquery 
Joining 4 tables 
1. Get id of “__Egi” 
2. Followed by ‘uid’ 
not 3. But not follow back 
4. Get name of ‘fid’ 
Return the results
76 
My Dream 
• Daily programming 
• Able to express complex tasks simply 
• Data access and analysis 
• Work as the most elegant query language 
• Able to access the wide range of data types in a 
unified way 
• Natural language processing 
• Programs that find interesting things 
• Programs that build math theories 
• Programs that generate programs 
• Able to handle complex structures intuitively as 
humans do in their mind 
• AI (Mathematical expression handling) 
• Able to handle various mathematical and abstract 
notions directly
[ANN]Articles on Egison will be on CodeIQ MAGAZINE 
77
78 
[ANN] We will post Egison problems on CodeIQ
79 
Thank you! 
Please try Egison and give us 
feedback! 
satoshi.egi@mail.rakuten.com
80 
Problem 
What is the 40th pair of prime 
numbers of the form (p, p+8)? 
Please try and answer to 
@Egison_Lang! 
e.g. [3, 11] [5, 13] [11, 19]…

More Related Content

Similar to Egison Pattern Matching in Ruby - Express Intuition Directly with Essentially New Syntax

Generating Natural-Language Text with Neural Networks
Generating Natural-Language Text with Neural NetworksGenerating Natural-Language Text with Neural Networks
Generating Natural-Language Text with Neural NetworksJonathan Mugan
 
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project ReportSouvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project ReportAkshit Arora
 
Applied category theory: the emerging science of compositionality
Applied category theory: the emerging science of compositionalityApplied category theory: the emerging science of compositionality
Applied category theory: the emerging science of compositionalitykenbot
 
Introducción a NLP (Natural Language Processing) en Azure
Introducción a NLP (Natural Language Processing) en AzureIntroducción a NLP (Natural Language Processing) en Azure
Introducción a NLP (Natural Language Processing) en AzurePlain Concepts
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Natural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachNatural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachMinhazul Arefin
 
Fashion product de-duplication with image similarity and LSH
Fashion product de-duplication with image similarity and LSHFashion product de-duplication with image similarity and LSH
Fashion product de-duplication with image similarity and LSHEddie Bell
 
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...BookNet Canada
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Tiểu Hổ
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 
Word2vec slide(lab seminar)
Word2vec slide(lab seminar)Word2vec slide(lab seminar)
Word2vec slide(lab seminar)Jinpyo Lee
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to ElixirDiacode
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14Anthony Ferrara
 

Similar to Egison Pattern Matching in Ruby - Express Intuition Directly with Essentially New Syntax (20)

NLP Bootcamp
NLP BootcampNLP Bootcamp
NLP Bootcamp
 
Generating Natural-Language Text with Neural Networks
Generating Natural-Language Text with Neural NetworksGenerating Natural-Language Text with Neural Networks
Generating Natural-Language Text with Neural Networks
 
Ruby Programming
Ruby ProgrammingRuby Programming
Ruby Programming
 
Apex code (Salesforce)
Apex code (Salesforce)Apex code (Salesforce)
Apex code (Salesforce)
 
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project ReportSouvenir's Booth - Algorithm Design and Analysis Project Project Report
Souvenir's Booth - Algorithm Design and Analysis Project Project Report
 
NPTEL complete.pptx.pptx
NPTEL complete.pptx.pptxNPTEL complete.pptx.pptx
NPTEL complete.pptx.pptx
 
Applied category theory: the emerging science of compositionality
Applied category theory: the emerging science of compositionalityApplied category theory: the emerging science of compositionality
Applied category theory: the emerging science of compositionality
 
Introducción a NLP (Natural Language Processing) en Azure
Introducción a NLP (Natural Language Processing) en AzureIntroducción a NLP (Natural Language Processing) en Azure
Introducción a NLP (Natural Language Processing) en Azure
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Natural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning ApproachNatural Language Query to SQL conversion using Machine Learning Approach
Natural Language Query to SQL conversion using Machine Learning Approach
 
Fashion product de-duplication with image similarity and LSH
Fashion product de-duplication with image similarity and LSHFashion product de-duplication with image similarity and LSH
Fashion product de-duplication with image similarity and LSH
 
FULL DOCUMENT.docx
FULL DOCUMENT.docxFULL DOCUMENT.docx
FULL DOCUMENT.docx
 
NPTEL_SEM_3.pdf
NPTEL_SEM_3.pdfNPTEL_SEM_3.pdf
NPTEL_SEM_3.pdf
 
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
Word2vec slide(lab seminar)
Word2vec slide(lab seminar)Word2vec slide(lab seminar)
Word2vec slide(lab seminar)
 
Introduction to Elixir
Introduction to ElixirIntroduction to Elixir
Introduction to Elixir
 
Init() Day 4
Init() Day 4Init() Day 4
Init() Day 4
 
Beyond design patterns phpnw14
Beyond design patterns   phpnw14Beyond design patterns   phpnw14
Beyond design patterns phpnw14
 

More from Rakuten Group, Inc.

コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話Rakuten Group, Inc.
 
楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のりRakuten Group, Inc.
 
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Rakuten Group, Inc.
 
DataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みDataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みRakuten Group, Inc.
 
大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開Rakuten Group, Inc.
 
楽天における大規模データベースの運用
楽天における大規模データベースの運用楽天における大規模データベースの運用
楽天における大規模データベースの運用Rakuten Group, Inc.
 
楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャーRakuten Group, Inc.
 
楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割Rakuten Group, Inc.
 
Rakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Group, Inc.
 
The Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfThe Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfRakuten Group, Inc.
 
Supporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfSupporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfRakuten Group, Inc.
 
Making Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfMaking Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfRakuten Group, Inc.
 
How We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfHow We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfRakuten Group, Inc.
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoRakuten Group, Inc.
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoRakuten Group, Inc.
 
Introduction of GORA API Group technology
Introduction of GORA API Group technologyIntroduction of GORA API Group technology
Introduction of GORA API Group technologyRakuten Group, Inc.
 
100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情Rakuten Group, Inc.
 
社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャーRakuten Group, Inc.
 

More from Rakuten Group, Inc. (20)

コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
 
楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり楽天における安全な秘匿情報管理への道のり
楽天における安全な秘匿情報管理への道のり
 
What Makes Software Green?
What Makes Software Green?What Makes Software Green?
What Makes Software Green?
 
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
 
DataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組みDataSkillCultureを浸透させる楽天の取り組み
DataSkillCultureを浸透させる楽天の取り組み
 
大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開大規模なリアルタイム監視の導入と展開
大規模なリアルタイム監視の導入と展開
 
楽天における大規模データベースの運用
楽天における大規模データベースの運用楽天における大規模データベースの運用
楽天における大規模データベースの運用
 
楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー楽天サービスを支えるネットワークインフラストラクチャー
楽天サービスを支えるネットワークインフラストラクチャー
 
楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割楽天の規模とクラウドプラットフォーム統括部の役割
楽天の規模とクラウドプラットフォーム統括部の役割
 
Rakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdfRakuten Services and Infrastructure Team.pdf
Rakuten Services and Infrastructure Team.pdf
 
The Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdfThe Data Platform Administration Handling the 100 PB.pdf
The Data Platform Administration Handling the 100 PB.pdf
 
Supporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdfSupporting Internal Customers as Technical Account Managers.pdf
Supporting Internal Customers as Technical Account Managers.pdf
 
Making Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdfMaking Cloud Native CI_CD Services.pdf
Making Cloud Native CI_CD Services.pdf
 
How We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdfHow We Defined Our Own Cloud.pdf
How We Defined Our Own Cloud.pdf
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech info
 
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech infoTravel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech info
 
OWASPTop10_Introduction
OWASPTop10_IntroductionOWASPTop10_Introduction
OWASPTop10_Introduction
 
Introduction of GORA API Group technology
Introduction of GORA API Group technologyIntroduction of GORA API Group technology
Introduction of GORA API Group technology
 
100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情100PBを越えるデータプラットフォームの実情
100PBを越えるデータプラットフォームの実情
 
社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー社内エンジニアを支えるテクニカルアカウントマネージャー
社内エンジニアを支えるテクニカルアカウントマネージャー
 

Recently uploaded

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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.pptxEarley Information Science
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
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 RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
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 2024Rafal Los
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
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...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 

Recently uploaded (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
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...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 

Egison Pattern Matching in Ruby - Express Intuition Directly with Essentially New Syntax

  • 1. Egison Pattern Matching in Ruby - Express Intuition Directly with Essentially New Syntax - Vol.01 Sep/18/2014 Satoshi Egi Rakuten Institute of Technology http://rit.rakuten.co.jp/
  • 2. 2 Self-Introduction Name Satoshi Egi (江木 聡志) Association Rakuten Institute of Technology (楽天技術研究所) Education Majored Computer Science in the University of Tokyo Interests Programming Languages, AI (Mathematics) Website http://www.egison.org/~egi/
  • 3. 3 Very Quick Introduction of Today’s Contents I have created the programming language that realized non-linear pattern-matching even against data that have no standard form. Non-linear patterns allow multiple occurrences of same variables in a pattern Enumerate the elements of the collection ‘xs’ that appear more than twice (match-all xs (multiset integer)! [<cons $x <cons ,x _>> x])! Egison pairs = []! (1..n).each do |i|! (i..n).each do |j|! if xs[i] == xs[j]! pairs = pairs +! xs[i]! end! end! end! Ruby
  • 4. 4 Very Quick Introduction of Today’s Contents I have implemented the same feature in Ruby! The source code on GitHub! https://github.com/egison/egison-ruby Enumerate the elements of the collection ‘xs’ that appear more than twice match_all(xs) do! with(Multiset.(_x,__x, *_)) { x }! end! Ruby with Egison gem pairs = []! (1..n).each do |i|! (i..n).each do |j|! if xs[i] == xs[j]! pairs = pairs +! xs[i]! end! end! end! Ruby
  • 5. 5 Very Quick Introduction of Today’s Contents Poker hands analyzer with a single expression in Ruby! Our pattern-matching expression represents all hands in a single pattern
  • 6. 6 Very Quick Introduction of Today’s Contents We can also pattern-match against infinite streams. … , x, x + 2, …
  • 7. 7 Source and English Document are on GitHub https://github.com/egison/egison-ruby
  • 8. 8 Please Check My Blog Article, too
  • 9. 9 We wrote also Japanese Documents on Qiita 1,0004 views, 185 Hatena Bookmarks!
  • 10. 10 Table of Contents 1. Introduction - What is Pattern Matching? 2. Egison Pattern Matching in Ruby 3. Let’s Try Egison Gem 4. Future Goal – Application of Egison
  • 11. 11 Table of Contents 1. Introduction - What is Pattern Matching? 2. Egison Pattern Matching in Ruby 3. Let’s Try Egison Gem 4. Future Goal – Application of Egison
  • 12. 12 What is Pattern Matching? A feature of programming languages that simplifies programs. • Data Decomposition • Pattern-matching enables us to extract and examine the value of an instance variable very easily • Conditional Branches • Pattern-matching eliminates nested and complex conditional branches
  • 19. 19 Flow of Pattern Matching fail
  • 20. 20 Flow of Pattern Matching success
  • 22. 22 Flow of Pattern Matching fail
  • 23. 23 Flow of Pattern Matching fail
  • 24. 24 Flow of Pattern Matching fail
  • 25. 25 Flow of Pattern Matching fail
  • 26. 26 Flow of Pattern Matching success
  • 28. 28 Table of Contents 1. Introduction - What is Pattern Matching? 2. Egison Pattern Matching in Ruby 3. Let’s Try Egison Gem 4. Future Goal – Application of Egison
  • 29. 29 The Features of Egison Pattern-Matching in Ruby We have features in addition to simplification of data decomposition and conditional branches • Customizable Way of Pattern-Matching • We can do pattern-matching against not only fixed data such as lists but also multisets and sets that have multiple ways of decomposition • Non-Linear Pattern-Matching • We allow multiple occurrences of same variables in patterns • Pattern-Matching with Backtracking • We allow multiple results of pattern-matching even infinite results
  • 30. 30 Customizable Pattern Matching For Various Data We can define how to pattern-match for each data types
  • 31. 31 Pattern Matching with Multiple Results We can handle multiple results of pattern-matching
  • 32. 32 Element Patterns and Collection Patterns A literal that starts with ‘_’ is a pattern-variable. We can refer the result of pattern-matching through them.
  • 33. 33 Element Patterns and Collection Patterns A subcollection pattern matches the subcollection of the target array. A subcollection pattern starts with ‘*’.
  • 34. 34 Element Patterns and Collection Patterns A literal that starts with ‘_’ is a pattern-variable. We can refer the result of pattern-matching through them.
  • 35. 35 Element Patterns and Collection Patterns A subcollection pattern matches the subcollection of the target array. A subcollection pattern starts with ‘*’.
  • 36. 36 Combinations with Pattern Matching … , x, …, y, … … , x, …, y, …, z, …
  • 37. 37 Non-Linear Pattern Matching A Pattern whose form is ‘__("...")’ is a value pattern
  • 38. 38 Non-Linear Pattern Matching A Pattern whose form is ‘__("...")’ is a value pattern We can omit (“ and “) when enclosed with them is a single variable
  • 39. 39 Poker Hands Analyzer in Ruby
  • 40. 40 The Pattern for Straight Flash Pattern for straight flash
  • 41. 41 The Pattern for Straight Flash Pattern for straight flash
  • 42. 42 Poker Hands Analyzer in Ruby Same suit with $s
  • 43. Numbers are serial from $n 43 Poker Hands Analyzer in Ruby Same suit with $s We can write any expression after ‘__’
  • 44. 44 Poker Hands Analyzer in Ruby Pattern for two pairs
  • 45. 45 The Pattern for Two Pairs Pattern for two pairs
  • 46. 46 The Pattern for Two Pairs Pattern for two pairs Same number with $m Same number with $n
  • 47. 47 The Pattern for Two Pairs Pattern for two pairs Same number with $m Same number with $n Non-linear patterns have very strong power
  • 48. 48 Poker Hands Analyzer in Ruby Non-linear patterns enables to represent all hands in a single pattern
  • 49. Pattern Matching against Streams with Infinite Results We can also pattern-match against infinite streams. 49 … , x, x + 2, …
  • 50. 50 One More Interesting Demonstration We can also enumerate prime triplets using and-patterns and or-patterns effectively.
  • 51. 51 Table of Contents 1. Introduction - What is Pattern Matching? 2. Egison Pattern Matching in Ruby 3. Let’s Try Egison Gem 4. Future Goal – Application of Egison
  • 52. 52 Egison Gem is on GitHub https://github.com/egison/egison-ruby
  • 53. 53 Try Egison Gem! Egison Gem is written in pure Ruby. Installation is very easy via RubyGems. $ git clone https://github.com/egison/egison-ruby.git $ cd egison-ruby/ $ bundle install $ make $ ls sample/ … sample/poker_hands.rb … $ ruby sample/poker_hands.rb … We have prepared a lot of samples. Please try all of them.
  • 54. 54 Table of Contents 1. Introduction - What is Pattern Matching? 2. Egison Pattern Matching in Ruby 3. Let’s Try Egison Gem 4. Future Goal – Application of Egison
  • 55. 55 Introduction of the Egison Programming Language
  • 56. 56 Profile of Egison I have created Egison to represent human’s intuition directly. Paradigm Pattern-matching-oriented, Purely functional Author Satoshi Egi License MIT Version 3.3.12 (2014/9/18) First Released 2011/5/24 Filename Extension .egi Implemented in Haskell (about 3,500 lines)
  • 57. 57 The Additional Features of Pure Egison We have features in additon to simplification of data decomposition and conditional branches • Ways of Pattern-Matching is More Customizable • We can customize the way of pattern-matching against not only against collection such as lists, multisets and sets • Pattern Modularization with Lexical Scoping • We allow multiple occurrences of same variables in patterns
  • 58. 58 More complex example, Mahjong
  • 59. 59 More complex example, Mahjong Two same tiles Three consecutive tiles Three same tiles
  • 60. 60 More complex example, Mahjong Two same tiles Three consecutive tiles Three same tiles Seven twins or one twin + four shuntsu or kohtsu
  • 61. 61 More complex example, Mahjong Two same tiles Three consecutive tiles Three same tiles Seven twins or one twin + four shuntsu or kohtsu Pattern modularization makes programming more simple!
  • 62. 62 Egison on an online media
  • 63. 63 Egison on Hacker News Egison was actively discussed on Hacker News twice!
  • 64. 64 Access Map of the Website in This Half Year (2014/1/14 – 2014/7/14) Total session is 14,109
  • 65. 65 Egison will be taught in the University of Tokyo by Prof. Hagiya Egison will have big impact on the academic world, too!
  • 66. 66 Growth of Community in This Year (2013/11/15 – 2014/9/18) • Mailing List Members • Before: 12 – Only my friends • Current: 23 – Communicating in English • Stargazers on GitHub • Before: 12 – Only my friends • Current: 214 – People from all over the world!
  • 67. 67 My Mind Map on Programming Language
  • 68. 68 My Mind Map on Programming Language
  • 69. 69 My Mind Map on Programming Language Egison is pioneering this field!
  • 71. 71 There is a Wide Range of Application • Daily programming • Able to express complex tasks simply • Data access and analysis • Work as the most elegant query language • Able to access the wide range of data types in a unified way • Natural language processing • Able to handle complex structures intuitively as humans do in their mind • AI (Mathematical expression handling) • Able to handle various mathematical and abstract notions directly
  • 72. 72 Query example • Query that returns twitter users who are followed by “__Egi” but not follow back “__Egi”. User: id integer name string Follow: from_id integer to_id Integer
  • 73. 73 SQL version • Complex and difficult to understand • Complex where clause contains “NOT EXIST” • Subquery
  • 74. 74 Egison version • Very Simple • No where clauses • No subquery
  • 75. 75 Egison version • Very Simple • No where clauses • No subquery Joining 4 tables 1. Get id of “__Egi” 2. Followed by ‘uid’ not 3. But not follow back 4. Get name of ‘fid’ Return the results
  • 76. 76 My Dream • Daily programming • Able to express complex tasks simply • Data access and analysis • Work as the most elegant query language • Able to access the wide range of data types in a unified way • Natural language processing • Programs that find interesting things • Programs that build math theories • Programs that generate programs • Able to handle complex structures intuitively as humans do in their mind • AI (Mathematical expression handling) • Able to handle various mathematical and abstract notions directly
  • 77. [ANN]Articles on Egison will be on CodeIQ MAGAZINE 77
  • 78. 78 [ANN] We will post Egison problems on CodeIQ
  • 79. 79 Thank you! Please try Egison and give us feedback! satoshi.egi@mail.rakuten.com
  • 80. 80 Problem What is the 40th pair of prime numbers of the form (p, p+8)? Please try and answer to @Egison_Lang! e.g. [3, 11] [5, 13] [11, 19]…