SlideShare a Scribd company logo
1 of 22
Download to read offline
XMF: A Language for Language Oriented
           Programming

                       Tony Clark1

     1 School   of Engineering and Information Sciences
                    University of Middlesex


                      July 25, 2011
Background



• UML 2.0 started around 2000.
• The 2U Submission: UML as family of languages.
• Aim: to merge modelling and programming.
• Tools: MMT, XMT, XMF.
• Programming language based on FP and OCL.
• Important features: meta-; reflection; OO.
• Xactium 2003–2008.
XMF

• Meta-Circular Language (like MOF and ECore).
• XCore Based on ObjvLisp.
• File based or world-state.
• Features for:
     • Packages of models/programs.
     • Higher-order operations.
     • OCL.
     • Meta-Object Prototcol (MOP).
     • Language Engineering (grammars, syntax processing).
     • Daemons (object listeners).
     • Pattern matching.
     • Code generation templates.
     • Threads.
     • XML processing (parsing).
     • Java integration.
Meta-language
Models



 1   context Root
 2     @Class Request
 3       @Attribute id : String end
 4       @Constructor(id) ! end
 5     end
 6
 7   context Root
 8     @Class RBuffer
 9       @Attribute requests : Seq(Request) end
10       @Constructor(requests) ! end
11     end
Behaviour
Programs: XOCL


 1   context RBuffer
 2     @Operation add(id:String)
 3       self.requests := requests + Seq{Request(id)}
 4     end
 5
 6   context RBuffer
 7     @Operation handle(id:String)
 8       @Match(requests) {
 9         R1 + Seq{Request(${id})} + R2 ->
10           self.requests := R1 + R2,
11         else self.error("No request with id " + id)
12       }
13     end
Failure



 1   context SeqOfElement
 2     @Operation removeDups()
 3       @Match(self) {
 4         S1 + Seq{x} + S2 + Seq{y} + S3 ->
 5           if x = y
 6           then (S1+S2+S3)->removeDups
 7           else fail()
 8           end,
 9         else self
10       }
11     end
Syntax Classes
Quasi-Quotes



 1   context Root
 2     @Operation add1_exp(exp:Performable):Performable
 3       [| 1 + <exp> |]
 4     end
 5
 6   context Root
 7     @Operation seq_exp(exps:Seq(Performable)):Performable
 8       exps->iterate(e x = [| Seq{} |] |
 9         [| <x>->including(<e>) |])
10     end
Grammars

 1   parserImport Parser::BNF;
 2   parserImport XOCL;
 3
 4   Root::g :=
 5     @Grammar
 6       Start ::= i=Int o=Op j=Int {
 7          @Case o of
 8            "+" do i + j end
 9            "*" do i * j end
10          end
11       }.
12       Op ::= ’+’ { "+" } | ’*’ { "*" }.
13     end;

     [ 1 ] XMF> g . parseString ( " 1 + 2 " , " S t a r t " , Seq { } ) ;
     3
     [ 1 ] XMF>
Match Language Construct
Match Syntax Class
 1   context Root
 2    @Class Match extends XOCL::Sugar
 3      @Attribute value : Performable end
 4      @Attribute arms : Seq(Arm) end
 5      @Attribute alt : Performable end
 6      @Constructor(value,arms,alt) ! end
 7      @Grammar extends OCL::OCL.grammar
 8        Match ::= e=Exp ’{’ as=Arm* ’else’ a=Exp ’}’ {
 9           Match(e,as,a)
10        }.
11        Arm ::= p=Pat ’->’ e=Exp ’,’ {Arm(p,e)}.
12        Pat ::= l=Atom (’+’ r=Pat {Append(l,r)} | {l}).
13        Pats ::= p=Pat ps=(’,’ Pat)* {Seq{p|ps}}.
14        Atom ::= i=Int {Const(i)}
15        | ’$’ ’{’ n=Name ’}’ {Ref(n)}
16        | v=Name (’(’ ps=Pats ’)’ {Cnstr(v,ps)} | {Var(v)})
17        | ’Seq{’ ps=Pats ’}’ {Patterns(ps)}.
18      end
19    end
Desugar



1   context Match
2     @Operation desugar()
3       [| let value = <value>
4          in <arms->iterate(arm exp=[| @Operation()
5                                         <alt>
6                                       end |]
7                           | arm.desugar(exp))>
8          end |]
9     end
Arms




1   context Arm
2     @Operation desugar(fail:Performable)
3       [| let fail = <fail>
4          in <pattern.match(exp)>
5          end |]
6     end
Constants




1   context Const
2     @Operation match(succ)
3       [| if value = <const.lift()>
4           then <succ>
5           else fail()
6           end |]
7       end
Variables and Refs


 1   context Var
 2     @Operation match(succ)
 3       [| let <name> = value in <succ> end |]
 4     end
 5
 6   context Ref
 7     @Operation match(succ)
 8       [| if value = <OCL::Var(name)>
 9          then <succ>
10          else fail()
11          end |]
12     end
Splits

 1   context SeqOfElement
 2     @Operation split()
 3       (0.to(self->size))->iterate(i pairs=Seq{} |
 4          pairs->including(Seq{self->take(i),
 5                               self->drop(i)}))
 6     end
 7
 8   context SeqOfElement
 9     @Operation select(succ,fail)
10       if self->isEmpty
11       then fail()
12       else succ(self->head,@Operation()
13                              self->tail.select(succ,fail)
14                            end)
15       end
16     end
Append

 1   context Append
 2     @Operation match(succ)
 3       [| if value.isKindOf(Seq(Element))
 4          then
 5            value->split.select(
 6              @Operation(pair,fail)
 7                let value = pair->at(0)
 8                in <left.match([| let value = pair->at(1)
 9                                  in <right.match(succ)>
10                                  end |])>
11                end
12              end,fail)
13          else fail()
14          end |]
15     end
Patterns



 1   context Patterns
 2    @Operation match(succ)
 3      [| if value.isKindOf(Seq(Element)) andthen value->
            size = <patterns->size.lift()>
 4         then <(0.to(patterns->size-1))->iterate(i s=succ |
 5                [| let value = value->at(<i.lift()>)
 6                    in <patterns->at(i).match(succ)>
 7                    end |])>
 8         else fail()
 9         end |]
10    end
Constructors
 1   context Cnstr
 2    @Operation match(succ)
 3      [| if value.of() = Root.getElement(<name.lift()>)
 4          then <let c = Root.getElement(name)
 5                             .constructors
 6                             ->select(c |
 7                               c.names->size =
 8                               args->size)
 9                             ->asSeq->head
10                in (0.to(args->size-1))->iterate(i exp=succ|
11                      [| let value = value.<c.names->at(i)>
12                         in <args->at(i).match(succ)>
13                         end |])
14                end>
15          else fail()
16          end |]
17      end
18     end
Availability, Documentation, Research
http://www.eis.mdx.ac.uk/staffpages/tonyclark/




                     XPL

More Related Content

What's hot

Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
adrianoalmeida7
 

What's hot (20)

Programmation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScriptProgrammation fonctionnelle en JavaScript
Programmation fonctionnelle en JavaScript
 
The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196The Ring programming language version 1.7 book - Part 30 of 196
The Ring programming language version 1.7 book - Part 30 of 196
 
Практическое применения Akka Streams
Практическое применения Akka StreamsПрактическое применения Akka Streams
Практическое применения Akka Streams
 
«Практическое применение Akka Streams» — Алексей Романчук, 2ГИС
«Практическое применение Akka Streams» — Алексей Романчук, 2ГИС«Практическое применение Akka Streams» — Алексей Романчук, 2ГИС
«Практическое применение Akka Streams» — Алексей Романчук, 2ГИС
 
The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180The Ring programming language version 1.5.1 book - Part 32 of 180
The Ring programming language version 1.5.1 book - Part 32 of 180
 
Dts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlinDts x dicoding #2 memulai pemrograman kotlin
Dts x dicoding #2 memulai pemrograman kotlin
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Operation Flow @ ChicagoRoboto
Operation Flow @ ChicagoRobotoOperation Flow @ ChicagoRoboto
Operation Flow @ ChicagoRoboto
 
The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181The Ring programming language version 1.5.2 book - Part 177 of 181
The Ring programming language version 1.5.2 book - Part 177 of 181
 
The Ring programming language version 1.9 book - Part 91 of 210
The Ring programming language version 1.9 book - Part 91 of 210The Ring programming language version 1.9 book - Part 91 of 210
The Ring programming language version 1.9 book - Part 91 of 210
 
ClojurianからみたElixir
ClojurianからみたElixirClojurianからみたElixir
ClojurianからみたElixir
 
Into Clojure
Into ClojureInto Clojure
Into Clojure
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184The Ring programming language version 1.5.3 book - Part 88 of 184
The Ring programming language version 1.5.3 book - Part 88 of 184
 
The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210The Ring programming language version 1.9 book - Part 42 of 210
The Ring programming language version 1.9 book - Part 42 of 210
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
The Magic Of Elixir
The Magic Of ElixirThe Magic Of Elixir
The Magic Of Elixir
 

Viewers also liked

Viewers also liked (6)

Dsl tutorial
Dsl tutorialDsl tutorial
Dsl tutorial
 
Kiss at oopsla 09
Kiss at oopsla 09Kiss at oopsla 09
Kiss at oopsla 09
 
Leap isec 2011
Leap isec 2011Leap isec 2011
Leap isec 2011
 
Dsl overview
Dsl overviewDsl overview
Dsl overview
 
Ast 09
Ast 09Ast 09
Ast 09
 
Hcse pres
Hcse presHcse pres
Hcse pres
 

Similar to Patterns 200711

ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
qmmr
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
Takayuki Goto
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Anton Shemerey
 

Similar to Patterns 200711 (20)

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)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)
 
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term RewritingCS4200 2019 | Lecture 5 | Transformation by Term Rewriting
CS4200 2019 | Lecture 5 | Transformation by Term Rewriting
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term RewritingCompiler Construction | Lecture 5 | Transformation by Term Rewriting
Compiler Construction | Lecture 5 | Transformation by Term Rewriting
 
Clojure for Data Science
Clojure for Data ScienceClojure for Data Science
Clojure for Data Science
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
ES6 Simplified
ES6 SimplifiedES6 Simplified
ES6 Simplified
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
 
Functional techniques in Ruby
Functional techniques in RubyFunctional techniques in Ruby
Functional techniques in Ruby
 
ECMAScript2015
ECMAScript2015ECMAScript2015
ECMAScript2015
 
Functional Operations - Susan Potter
Functional Operations - Susan PotterFunctional Operations - Susan Potter
Functional Operations - Susan Potter
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)オープンデータを使ったモバイルアプリ開発(応用編)
オープンデータを使ったモバイルアプリ開発(応用編)
 
Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?Scala - en bedre og mere effektiv Java?
Scala - en bedre og mere effektiv Java?
 
More than syntax
More than syntaxMore than syntax
More than syntax
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
PythonOOP
PythonOOPPythonOOP
PythonOOP
 
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code styleRuby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
Ruby: OOP, metaprogramming, blocks, iterators, mix-ins, duck typing. Code style
 

More from ClarkTony

Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
ClarkTony
 
LEAP A Language for Architecture Design, Simulation and Analysis
LEAP A Language for Architecture Design, Simulation and AnalysisLEAP A Language for Architecture Design, Simulation and Analysis
LEAP A Language for Architecture Design, Simulation and Analysis
ClarkTony
 
A Common Basis for Modelling Service-Oriented and Event-Driven Architecture
A Common Basis for Modelling Service-Oriented and Event-Driven ArchitectureA Common Basis for Modelling Service-Oriented and Event-Driven Architecture
A Common Basis for Modelling Service-Oriented and Event-Driven Architecture
ClarkTony
 
Context Aware Reactive Applications
Context Aware Reactive ApplicationsContext Aware Reactive Applications
Context Aware Reactive Applications
ClarkTony
 
Model Slicing
Model SlicingModel Slicing
Model Slicing
ClarkTony
 
Kings 120711
Kings 120711Kings 120711
Kings 120711
ClarkTony
 
Iswim for testing
Iswim for testingIswim for testing
Iswim for testing
ClarkTony
 
Iswim for testing
Iswim for testingIswim for testing
Iswim for testing
ClarkTony
 
Mcms and ids sig
Mcms and ids sigMcms and ids sig
Mcms and ids sig
ClarkTony
 
Reverse engineering and theory building v3
Reverse engineering and theory building v3Reverse engineering and theory building v3
Reverse engineering and theory building v3
ClarkTony
 
Onward presentation.en
Onward presentation.enOnward presentation.en
Onward presentation.en
ClarkTony
 
Formalizing homogeneous language embeddings
Formalizing homogeneous language embeddingsFormalizing homogeneous language embeddings
Formalizing homogeneous language embeddings
ClarkTony
 
Filmstrip testing
Filmstrip testingFilmstrip testing
Filmstrip testing
ClarkTony
 
Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory building
ClarkTony
 
Code gen 09 kiss results
Code gen 09   kiss resultsCode gen 09   kiss results
Code gen 09 kiss results
ClarkTony
 

More from ClarkTony (20)

The Uncertain Enterprise
The Uncertain EnterpriseThe Uncertain Enterprise
The Uncertain Enterprise
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural Simulation
 
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
Context-Aware Content-Centric Collaborative Workflow Management for Mobile De...
 
LEAP A Language for Architecture Design, Simulation and Analysis
LEAP A Language for Architecture Design, Simulation and AnalysisLEAP A Language for Architecture Design, Simulation and Analysis
LEAP A Language for Architecture Design, Simulation and Analysis
 
A Common Basis for Modelling Service-Oriented and Event-Driven Architecture
A Common Basis for Modelling Service-Oriented and Event-Driven ArchitectureA Common Basis for Modelling Service-Oriented and Event-Driven Architecture
A Common Basis for Modelling Service-Oriented and Event-Driven Architecture
 
Context Aware Reactive Applications
Context Aware Reactive ApplicationsContext Aware Reactive Applications
Context Aware Reactive Applications
 
Model Slicing
Model SlicingModel Slicing
Model Slicing
 
Kings 120711
Kings 120711Kings 120711
Kings 120711
 
Iswim for testing
Iswim for testingIswim for testing
Iswim for testing
 
Iswim for testing
Iswim for testingIswim for testing
Iswim for testing
 
Mcms and ids sig
Mcms and ids sigMcms and ids sig
Mcms and ids sig
 
Ocl 09
Ocl 09Ocl 09
Ocl 09
 
Scam 08
Scam 08Scam 08
Scam 08
 
Reverse engineering and theory building v3
Reverse engineering and theory building v3Reverse engineering and theory building v3
Reverse engineering and theory building v3
 
Onward presentation.en
Onward presentation.enOnward presentation.en
Onward presentation.en
 
Formalizing homogeneous language embeddings
Formalizing homogeneous language embeddingsFormalizing homogeneous language embeddings
Formalizing homogeneous language embeddings
 
Filmstrip testing
Filmstrip testingFilmstrip testing
Filmstrip testing
 
Dsm as theory building
Dsm as theory buildingDsm as theory building
Dsm as theory building
 
Code gen 09 kiss results
Code gen 09   kiss resultsCode gen 09   kiss results
Code gen 09 kiss results
 
Cg 2011
Cg 2011Cg 2011
Cg 2011
 

Recently uploaded

Recently uploaded (20)

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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Patterns 200711

  • 1. XMF: A Language for Language Oriented Programming Tony Clark1 1 School of Engineering and Information Sciences University of Middlesex July 25, 2011
  • 2. Background • UML 2.0 started around 2000. • The 2U Submission: UML as family of languages. • Aim: to merge modelling and programming. • Tools: MMT, XMT, XMF. • Programming language based on FP and OCL. • Important features: meta-; reflection; OO. • Xactium 2003–2008.
  • 3. XMF • Meta-Circular Language (like MOF and ECore). • XCore Based on ObjvLisp. • File based or world-state. • Features for: • Packages of models/programs. • Higher-order operations. • OCL. • Meta-Object Prototcol (MOP). • Language Engineering (grammars, syntax processing). • Daemons (object listeners). • Pattern matching. • Code generation templates. • Threads. • XML processing (parsing). • Java integration.
  • 5. Models 1 context Root 2 @Class Request 3 @Attribute id : String end 4 @Constructor(id) ! end 5 end 6 7 context Root 8 @Class RBuffer 9 @Attribute requests : Seq(Request) end 10 @Constructor(requests) ! end 11 end
  • 7. Programs: XOCL 1 context RBuffer 2 @Operation add(id:String) 3 self.requests := requests + Seq{Request(id)} 4 end 5 6 context RBuffer 7 @Operation handle(id:String) 8 @Match(requests) { 9 R1 + Seq{Request(${id})} + R2 -> 10 self.requests := R1 + R2, 11 else self.error("No request with id " + id) 12 } 13 end
  • 8. Failure 1 context SeqOfElement 2 @Operation removeDups() 3 @Match(self) { 4 S1 + Seq{x} + S2 + Seq{y} + S3 -> 5 if x = y 6 then (S1+S2+S3)->removeDups 7 else fail() 8 end, 9 else self 10 } 11 end
  • 10. Quasi-Quotes 1 context Root 2 @Operation add1_exp(exp:Performable):Performable 3 [| 1 + <exp> |] 4 end 5 6 context Root 7 @Operation seq_exp(exps:Seq(Performable)):Performable 8 exps->iterate(e x = [| Seq{} |] | 9 [| <x>->including(<e>) |]) 10 end
  • 11. Grammars 1 parserImport Parser::BNF; 2 parserImport XOCL; 3 4 Root::g := 5 @Grammar 6 Start ::= i=Int o=Op j=Int { 7 @Case o of 8 "+" do i + j end 9 "*" do i * j end 10 end 11 }. 12 Op ::= ’+’ { "+" } | ’*’ { "*" }. 13 end; [ 1 ] XMF> g . parseString ( " 1 + 2 " , " S t a r t " , Seq { } ) ; 3 [ 1 ] XMF>
  • 13. Match Syntax Class 1 context Root 2 @Class Match extends XOCL::Sugar 3 @Attribute value : Performable end 4 @Attribute arms : Seq(Arm) end 5 @Attribute alt : Performable end 6 @Constructor(value,arms,alt) ! end 7 @Grammar extends OCL::OCL.grammar 8 Match ::= e=Exp ’{’ as=Arm* ’else’ a=Exp ’}’ { 9 Match(e,as,a) 10 }. 11 Arm ::= p=Pat ’->’ e=Exp ’,’ {Arm(p,e)}. 12 Pat ::= l=Atom (’+’ r=Pat {Append(l,r)} | {l}). 13 Pats ::= p=Pat ps=(’,’ Pat)* {Seq{p|ps}}. 14 Atom ::= i=Int {Const(i)} 15 | ’$’ ’{’ n=Name ’}’ {Ref(n)} 16 | v=Name (’(’ ps=Pats ’)’ {Cnstr(v,ps)} | {Var(v)}) 17 | ’Seq{’ ps=Pats ’}’ {Patterns(ps)}. 18 end 19 end
  • 14. Desugar 1 context Match 2 @Operation desugar() 3 [| let value = <value> 4 in <arms->iterate(arm exp=[| @Operation() 5 <alt> 6 end |] 7 | arm.desugar(exp))> 8 end |] 9 end
  • 15. Arms 1 context Arm 2 @Operation desugar(fail:Performable) 3 [| let fail = <fail> 4 in <pattern.match(exp)> 5 end |] 6 end
  • 16. Constants 1 context Const 2 @Operation match(succ) 3 [| if value = <const.lift()> 4 then <succ> 5 else fail() 6 end |] 7 end
  • 17. Variables and Refs 1 context Var 2 @Operation match(succ) 3 [| let <name> = value in <succ> end |] 4 end 5 6 context Ref 7 @Operation match(succ) 8 [| if value = <OCL::Var(name)> 9 then <succ> 10 else fail() 11 end |] 12 end
  • 18. Splits 1 context SeqOfElement 2 @Operation split() 3 (0.to(self->size))->iterate(i pairs=Seq{} | 4 pairs->including(Seq{self->take(i), 5 self->drop(i)})) 6 end 7 8 context SeqOfElement 9 @Operation select(succ,fail) 10 if self->isEmpty 11 then fail() 12 else succ(self->head,@Operation() 13 self->tail.select(succ,fail) 14 end) 15 end 16 end
  • 19. Append 1 context Append 2 @Operation match(succ) 3 [| if value.isKindOf(Seq(Element)) 4 then 5 value->split.select( 6 @Operation(pair,fail) 7 let value = pair->at(0) 8 in <left.match([| let value = pair->at(1) 9 in <right.match(succ)> 10 end |])> 11 end 12 end,fail) 13 else fail() 14 end |] 15 end
  • 20. Patterns 1 context Patterns 2 @Operation match(succ) 3 [| if value.isKindOf(Seq(Element)) andthen value-> size = <patterns->size.lift()> 4 then <(0.to(patterns->size-1))->iterate(i s=succ | 5 [| let value = value->at(<i.lift()>) 6 in <patterns->at(i).match(succ)> 7 end |])> 8 else fail() 9 end |] 10 end
  • 21. Constructors 1 context Cnstr 2 @Operation match(succ) 3 [| if value.of() = Root.getElement(<name.lift()>) 4 then <let c = Root.getElement(name) 5 .constructors 6 ->select(c | 7 c.names->size = 8 args->size) 9 ->asSeq->head 10 in (0.to(args->size-1))->iterate(i exp=succ| 11 [| let value = value.<c.names->at(i)> 12 in <args->at(i).match(succ)> 13 end |]) 14 end> 15 else fail() 16 end |] 17 end 18 end