SlideShare a Scribd company logo
1 of 44
Download to read offline
PISTACHE
A π-Calculus Internal Domain Specific Language for Scala
• PedroMatiello
 pmatiello@gmail.com

• AnaCristina de Melo
 acvm@ime.usp.br

• http://code.google.com/p/pistache/
INTRODUCTION



• Pistacheis an implementation of the π-Calculus as a domain
 specific language hosted in Scala
INTRODUCTION



• Itprovides π-Calculus’ abstractions for concurrent
  computation within the Scala programming language
π-CALCULUS
• π-Calculus
           is a formal language for describing
 concurrent computation with dynamic
 reconfiguration
• Agentscommunicate by exchanging names through
 channels (which are also names)

• Connections between agents may change in the
 course of the computation
AGENTS
  0             Nil
 α.P         Prefix
P+Q           Sum
P|Q          Parallel
(νx)P      Restriction
[x=y].P      Match
[x≠y].P     Mismatch
PREFIXES

_
yx          Output

y(x)        Input

 τ          Silent
EXAMPLE


• The Agents:
                _
 C = (νz) y(p).pz
     _
 S = yx.S
 P = x(w).α.P

• The
   composition:
 C|S|P


                         Example adapted from: An Introduction to the pi-Calculus, by Joachim Parrow
SCALA
• Scalais a general-purpose programming language
 providing features both of object-oriented and
 functional programming
• Flexible   syntax

• Statically-typed

• Runs   on the Java Virtual Machine
• Actively-developed

• Growing   community
PISTACHE
• Pistacheis an implementation of π-Calculus as an
 internal Domain Specific Language for Scala
AGENT DEFINITION
val P = Agent(...)


lazy val recP:Agent = Agent(...)


val restrP = Agent {
    val restrictedName = Name(...)
    ...
}
NAMES
val name = Name(some_object)


val name = Name[Type]


name := other_object


value = name.value
CHANNELS
val y = Link[Type]

                                _
y~x                             yx


y(x)                            y(x)
SILENT TRANSITIONS


val silent = Action{ doSomething() }   τ
CONCATENATION


val P = Agent { p1 * p2 * Q }   P = α.β.Q
COMPOSITION


val P = Agent { Q | R | S }   P=Q|R|S
SUMMATION


val P = Agent {
    (p1 :: Q) + (p2 :: R) + (p3 :: S)   P = αQ + βR + γS
}
MATCHING


val P = Agent(If (x==y) {Q})   P = [x=y] Q
EXAMPLE


• The Agents:
                _
 C = (νz) y(p).pz
     _
 S = yx.S
 P = x(w).α.P

• The
   composition:
 C|S|P
EXAMPLE


val y = Link[Link[String]]
val x = Link[String]
EXAMPLE

val y = Link[Link[String]]
val x = Link[String]


val C = Agent {
  val p = Name[Link[String]]
                                                    _
                                       C = (νz) y(p).pz
  val z = "message"
  y(p) * p~z
}
EXAMPLE

val y = Link[Link[String]]
val x = Link[String]

val C = Agent {
  val p = Name[Link[String]]
                                             _
                                         S = yx.S
  y(p) * p~"message"
}


lazy val S:Agent = Agent { y~x*S }
EXAMPLE
val y = Link[Link[String]]
val x = Link[String]

val C = Agent {
  val p = Name[Link[String]]
  y(p) * p~"message"
}

lazy val S:Agent = Agent { y~x*S }


lazy val P:Agent = Agent {
  val w = Name[String]
                                               P = x(w).α.P
  val act = Action { println(msg.value) }
  x(w) * act * P
}
EXAMPLE
val y = Link[Link[String]]
val x = Link[String]

val C = Agent {
  val p = Name[Link[String]]
  y(p) * p~"message"
}

lazy val S:Agent = Agent { y~x*S }

lazy val P:Agent = Agent {
  val msg = Name[String]                              C|S|P
  val act = Action { println(msg.value) }
  x(msg) * act * P
}


new ThreadedRunner(C | S | P) start
MESSAGE PASSING



• Channels   are implemented as shared buffers

• Communication    between agents is synchronous
MESSAGE PASSING

            _
     Output yx                 Input y(x)

Wait until y is empty   Wait until y is not empty

     Put x on y         Put the contents of y in x

 Signal y not empty          Signal y empty

Wait until y is empty
DATA STRUCTURE
val P = Agent ( p1 * p2 * p3 * Q )
DATA STRUCTURE
val P = Agent ( p1 * p2 * p3 * Q )
EXECUTION

def execute(agent:PiObject) {
  agent match {
    case ConcatenationAgent(left, right) => ...
    case CompositionAgent(left, right) => ...
        ...
    }
}
EXECUTION


case ConcatenationAgent(left, right) =>
  execute(left apply)
  execute(right apply)
EXECUTION


case CompositionAgent(left, right) =>
  executeInNewThread(left apply)
  executeInNewThread(right apply)
THREAD SPAWNING

def executeInNewThread(agent:PiObject) {

    val runnable = new Runnable() {
      override def run() { execute(agent) }
    }

    executor.execute(runnable)
}
THREAD SPAWNING

•   CachedThreadPool

    • Caches    finished threads

    • Reuses   cached threads

    • Creates   new threads if none are available

    • Deletesfrom the pool threads that have not been used
     reused for 60 seconds
THREAD SPAWNING

    Strategy       Time consumed for 100k agents



   new Thread               23 743 ms



CachedThreadPool             2 089 ms
CONCLUSION



• We   knew that:

 • Concurrent   programming is hard
CONCLUSION



• We   learned that:

 • Properabstractions can improve our understanding of
  concurrency and concurrent programs
CONCLUSION


• We   also learned that:

 • The
     abstractions present in π-Calculus provide a feasible
  model for concurrency in actual software programming
PISTACHE
     Pedro Matiello
Ana Cristina de Melo

More Related Content

What's hot

Performing calculations using java script
Performing calculations using java scriptPerforming calculations using java script
Performing calculations using java script
Jesus Obenita Jr.
 
SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegression
Daniel K
 

What's hot (19)

matlab code of shifting and folding of two sequences
matlab code of shifting and folding of two sequencesmatlab code of shifting and folding of two sequences
matlab code of shifting and folding of two sequences
 
Struct examples
Struct examplesStruct examples
Struct examples
 
MATLAB CODE OF Shifting sequence
MATLAB  CODE  OF Shifting sequenceMATLAB  CODE  OF Shifting sequence
MATLAB CODE OF Shifting sequence
 
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and SparkCrystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
Crystal Ball Event Prediction and Log Analysis with Hadoop MapReduce and Spark
 
Performing calculations using java script
Performing calculations using java scriptPerforming calculations using java script
Performing calculations using java script
 
Beginning Scala Svcc 2009
Beginning Scala Svcc 2009Beginning Scala Svcc 2009
Beginning Scala Svcc 2009
 
Rumus visual basic
Rumus visual basicRumus visual basic
Rumus visual basic
 
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
QA Fest 2018. Никита Кричко. Методология использования машинного обучения в н...
 
Lec21-CS110 Computational Engineering
Lec21-CS110 Computational EngineeringLec21-CS110 Computational Engineering
Lec21-CS110 Computational Engineering
 
Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器
 
Thesis PPT
Thesis PPTThesis PPT
Thesis PPT
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
SupportVectorRegression
SupportVectorRegressionSupportVectorRegression
SupportVectorRegression
 
Functional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks weekFunctional Programming in Javascript - IL Tech Talks week
Functional Programming in Javascript - IL Tech Talks week
 
Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011Functional Programming and Haskell - TWBR Away Day 2011
Functional Programming and Haskell - TWBR Away Day 2011
 
Functional programming in Swift
Functional programming in SwiftFunctional programming in Swift
Functional programming in Swift
 
The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30The Ring programming language version 1.4 book - Part 6 of 30
The Ring programming language version 1.4 book - Part 6 of 30
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Web futures
Web futuresWeb futures
Web futures
 

Similar to Pistache: A π-Calculus Internal Domain Specific Language for Scala

TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
Eelco Visser
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 

Similar to Pistache: A π-Calculus Internal Domain Specific Language for Scala (20)

Understanding distributed calculi in Haskell
Understanding distributed calculi in HaskellUnderstanding distributed calculi in Haskell
Understanding distributed calculi in Haskell
 
TI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretationTI1220 Lecture 9: Parsing & interpretation
TI1220 Lecture 9: Parsing & interpretation
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3
 
RChain - Understanding Distributed Calculi
RChain - Understanding Distributed CalculiRChain - Understanding Distributed Calculi
RChain - Understanding Distributed Calculi
 
Railroading into Scala
Railroading into ScalaRailroading into Scala
Railroading into Scala
 
Python to scala
Python to scalaPython to scala
Python to scala
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notation
 
Formal methods 5 - Pi calculus
Formal methods   5 - Pi calculusFormal methods   5 - Pi calculus
Formal methods 5 - Pi calculus
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
Introduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf TaiwanIntroduction to Scala for JCConf Taiwan
Introduction to Scala for JCConf Taiwan
 
Scala
ScalaScala
Scala
 
Advance Scala - Oleg Mürk
Advance Scala - Oleg MürkAdvance Scala - Oleg Mürk
Advance Scala - Oleg Mürk
 
Introduction to Quasiquotes
Introduction to QuasiquotesIntroduction to Quasiquotes
Introduction to Quasiquotes
 
Java gets a closure
Java gets a closureJava gets a closure
Java gets a closure
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 

Recently uploaded

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
FIDO Alliance
 

Recently uploaded (20)

Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...Hyatt driving innovation and exceptional customer experiences with FIDO passw...
Hyatt driving innovation and exceptional customer experiences with FIDO passw...
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 

Pistache: A π-Calculus Internal Domain Specific Language for Scala