SlideShare una empresa de Scribd logo
1 de 20
Phorms: Pattern Matching
Library for Pharo
Markiyan Rizun Camille Teruel, Gustavo Santos, Stéphane Ducasse1
Markiyan Rizun e-mail: mrizun@gmail.com download: http://smalltalkhub.com/#!/~CamilleTeruel/Patterns/
Pattern matching
Introduced in functional programming.
Mainly used for inductive definition of functions.
2
Pattern matching.
Example
3
fib n
| n == 0 = 1
| n == 1 = 1
| n >= 2 = fib (n-1) + fib (n-2)
Pattern matching4
Integrated in Newspeak, Scala.
Mainly used to decompose object data.
Pattern matching in Pharo5
•Source code rewriting
The Rewrite Engine
Pattern matching in Pharo.
Example
6
“matching part”
``@a > ``@b
ifTrue: [ ``@a ]
ifFalse: [ ``@b ]
“transforming part”
``@a max: ``@b
“input”
a > b
ifTrue: [ a ]
ifFalse: [ b ]
“result”
a max: b
The Rewrite Engine7
1. AST focused.
2. Sometimes confusing.
3. Patterns are not composable.
4. Debug and inspect are not
user-friendly.
5. Not extendable.
1. Efficient source
code rewriting.
2. Smalltalk style
syntax.
Solution8
•Patterns are objects
Phorms
Phorms.
Patterns
9
1 equals “equality”
p1 & p2 & … & pN “and”
p1 | p2 | … | pN “or”
Phorms.
Patterns
10
p1, p2, … , pN “list”
p1, (p2, p3) inList “nested list”
p1, p2 star, p3 “star list”
Phorms.
Patterns
11
pattern ==> [ :it :context |… ] “rewriting”
1 equals named: #aName “named”
#var any “any”
Phorms.
Matching
12
pattern match: anObject
Phorms.
Matching Example 1
13
1) pattern := 2 equals, 3 equals.
2) pattern match: 2@3.
Phorms.
Matching Example 1
14
2@3
2 3
2 equals, 3 equals
Phorms.
Matching Example 2
15
1) pattern := #var any, 5 equals.
2) ast := RBParser parseExpression:
3) ‘variable := 5’.
4) pattern match: ast.
Phorms.
Matching Example 2
16
variable := 5
variable 5
#var any, 5 equals
Phorms.
Rewriting
17
rewritingPattern rewrite: anObject
Rewriting pattern = match + transform.
Phorms.
Rewriting Example
18
1) match := #x any, #y any.
2) transform := [ :it :context| it y @ it x ].
4) pattern := match ==> transform .
5) pattern rewrite: 1@2.
Result: (2@1)
Phorms.
Conclusion
19
1. Rewrite anything!
2. Patterns are objects
(compose & convert).
3. User-friendly debug &
inspect.
4. Easily extendable
1. Not (yet!) AST
focused.
2. Sometimes bulky
code.
Markiyan Rizun e-mail: mrizun@gmail.com download: http://smalltalkhub.com/#!/~CamilleTeruel/Patterns/
20

Más contenido relacionado

La actualidad más candente (20)

Python intro ch_e_comp
Python intro ch_e_compPython intro ch_e_comp
Python intro ch_e_comp
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 
Howto argparse
Howto argparseHowto argparse
Howto argparse
 
Hacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitationHacker Thursdays: An introduction to binary exploitation
Hacker Thursdays: An introduction to binary exploitation
 
Python for loop
Python for loopPython for loop
Python for loop
 
Functions
FunctionsFunctions
Functions
 
Python programing
Python programingPython programing
Python programing
 
Introduction to Recursion (Python)
Introduction to Recursion (Python)Introduction to Recursion (Python)
Introduction to Recursion (Python)
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
AmI 2017 - Python basics
AmI 2017 - Python basicsAmI 2017 - Python basics
AmI 2017 - Python basics
 
Python
PythonPython
Python
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Python advance
Python advancePython advance
Python advance
 
python-message-0.1.0
python-message-0.1.0python-message-0.1.0
python-message-0.1.0
 
Python ppt
Python pptPython ppt
Python ppt
 
Looping statement in python
Looping statement in pythonLooping statement in python
Looping statement in python
 
Python language data types
Python language data typesPython language data types
Python language data types
 

Similar a Phorms: Pattern Matching Library for Pharo

Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in PythonSujith Kumar
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptxPadreBhoj
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameAntony Stubbs
 
Processing Regex Python
Processing Regex PythonProcessing Regex Python
Processing Regex Pythonprimeteacher32
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressionsKrishna Nanda
 
Mastering Grammars with PetitParser
Mastering Grammars with PetitParserMastering Grammars with PetitParser
Mastering Grammars with PetitParserLukas Renggli
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20Max Kleiner
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptxDurgaNayak4
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Philip Schwarz
 

Similar a Phorms: Pattern Matching Library for Pharo (20)

Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python basic
Python basicPython basic
Python basic
 
Template Haskell
Template HaskellTemplate Haskell
Template Haskell
 
unit-4 regular expression.pptx
unit-4 regular expression.pptxunit-4 regular expression.pptx
unit-4 regular expression.pptx
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
Processing Regex Python
Processing Regex PythonProcessing Regex Python
Processing Regex Python
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Ch2
Ch2Ch2
Ch2
 
Ch2 (1).ppt
Ch2 (1).pptCh2 (1).ppt
Ch2 (1).ppt
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python regular expressions
Python regular expressionsPython regular expressions
Python regular expressions
 
Mastering Grammars with PetitParser
Mastering Grammars with PetitParserMastering Grammars with PetitParser
Mastering Grammars with PetitParser
 
PHP Web Programming
PHP Web ProgrammingPHP Web Programming
PHP Web Programming
 
Maxbox starter20
Maxbox starter20Maxbox starter20
Maxbox starter20
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Regular_Expressions.pptx
Regular_Expressions.pptxRegular_Expressions.pptx
Regular_Expressions.pptx
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part ...
 
lab4_php
lab4_phplab4_php
lab4_php
 

Último

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 

Último (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 

Phorms: Pattern Matching Library for Pharo

Notas del editor

  1. Good day, everyone. I am Markiyan Rizun and today I would like to present a new pattern library, which is able to match and transform any object in Pharo.
  2. Originally, pattern matching facilities were introduced in functional programming and mainly used for inductive function definitions.
  3. For example, consider shown function written in Haskell, which returns Nth Fibonacci number. The function is implemented used pattern matching. Fib is a pattern that matches an integer n and depending on its value, certain action is executed. If n is 0 or 1 function returns 1, otherwise pattern matches recursively.
  4. Later, pattern matching was adapted to object-oriented world and integrated into many languages such as Newspeak and Scala. In OOP, the principle is to decompose object and to find parts of interest.
  5. Pattern matching facilities already exist in Pharo. We have The Rewrite Engine that focuses on source code rewriting, i.e., it specifically matches nodes in the Abstract Syntax Tree (AST) of Pharo, and we currently use it to refactor code.
  6. Consider the following example. Here we want to rewrite ifTrue:ifFalse: statement into max: message send, which is much better implementation of the same behavior. In order to do that we should apply the following pattern to the source code. We can clearly see that it is very similar to actual Pharo code and has the syntax that uses only few new symbols.
  7. The Rewrite Engine is an effective tool for code rewriting. What is even more, it enables us to create matching and transforming patterns with syntax that is as close to Smalltalk code as possible. The Rewrite Engine introduces only few new symbols. However, it has its limits. First, The Rewrite Engine works only with current AST implementation that we have in Pharo. Unfortunately, it is not possible to rewrite any other objects than ASTs. In addition, the simplicity of syntax and its similarity to Smalltalk code has its downside – the patterns are sometimes confusing. It is not always clear how certain pattern will behave when applied to specific AST. Moreover, the patterns implemented with The Rewrite Engine does not support composition. Also, debug and inspect with patterns is not very user-friendly. Finally, The Rewrite Engine itself is not extendable.
  8. To overcome the limits of The Rewrite Engine, we propose Phorms. Phorms is a general pattern library that is able to match not only ASTs, but also any other object in Pharo. Additionally, our library enables users to operate patterns like any other first-class objects; therefore, we compose, inspect, and debug them.
  9. Now, I propose to look at some of the patterns from our library. First, we have the simplest one – it is an equality pattern. The idea is that it matches objects that are equal to its wrapped object, in this case integer one. Also, we have and pattern that successfully matches if all of its sub-patterns matches. The same is with or pattern. It matches if at least one of its sub-patterns matches.
  10. The main pattern of our library is list pattern. It consists out of other patterns. In order to match an object, list pattern deconstructs it into smaller parts, and each sub-pattern of list pattern matches each part of the object separately. Then, we have nested list, meaning that list pattern contains another list pattern. And, finally, star list pattern: the principle is the same as in list pattern. The key difference is that list uses one sub-pattern to match one part of deconstructed object, when star pattern may use one sub-pattern to match any number of objects. The sub-pattern marked as star will match as few parts of object as possible to make the whole pattern match successfully.
  11. In addition, we have rewriting pattern. It has two parts: matching, which is a pattern that matches an object, and transforming, which is a block that constructs new object. The block has two arguments. First – it – is the object that we match, second – context – provides additional information and gives access to metavariables, which we can create using the next pattern – named pattern. It wraps another pattern and gives a name (a metavariable) to a successful match for later reference in the transformation side. Plus there is any pattern that matches any object.
  12. In order to perform matching we send #match: message to a pattern with an argument, which is an object that we want to match. In result of such message send, we get either success or failure.
  13. For example, consider code presented on this slide. In the first line, we create two equality patterns and concatenate them into a list pattern, using comma. In line two, we match this pattern with object – a point 2@3.
  14. During the matching in the line two, we deconstruct an object, and match each part of this object with parts of pattern – sub-patterns.
  15. Let us look at another example: here we have pattern that matches AST. First sub-pattern of list pattern in the first line is #var any that matches any object. In the second and third lines, we create AST that represents assignment of integer five to some variable.
  16. During the matching in the line four, we deconstruct an AST same as in previous example, and match each part of this object with sub-pattern. We break down our AST into two parts: variable and value. Each of them successfully matches sub-patterns respectively. Therefore, as you can see we used Phorms to match a point (generic object) and an AST (source code).
  17. Now let us move on to rewriting. In order to match and transform an object we send #rewrite: message to a rewriting pattern with an argument that is an object, which we want to transform. Again, rewriting pattern consists of two parts: matching, which is a pattern that matches an object, and transforming, which is a block that constructs new object.
  18. In our example, the matching part is a list pattern with two sub-patterns that match any two objects. The transforming part is a block that returns a point with reverted coordinates. Here we use it in order to access the coordinates of matched point. In the line five, we rewrite a point 1@2 and get a point 2@1.
  19. To sum up, we introduce new pattern library called Phorms into Pharo, which is capable to match and transform any objects, whether it is built-in Pharo object or user-created. Of course, this applies to ASTs as well, so we can perform source code rewriting. What is even more, patterns are first-class objects. Therefore, we can compose patterns using a number of different predefined combinators and convert them too. The patterns can be inspected and they provide useful information. Matching process can be easily debugged. Of course, Phorms library is extendable, so you are welcome to implement pattern types or combinators. As for disadvantages of our implementation: firstly, for now there is no specific API / syntax for AST rewriting, therefore in order to perform source code transformation one may have to implement bulky patterns. In the future, though, we plan to implement an extension to our library, which would facilitate AST rewriting.
  20. Thank you for your attention. Maybe there are some questions?