SlideShare a Scribd company logo
1 of 25
Download to read offline
Living with spec
@sbelak
simon@goopti.com
Parsing with Derivatives
A Functional Pearl
Matthew Might David Darais
University of Utah
might@cs.utah.edu, david.darais@gmail.com
Daniel Spiewak
University of Wisconsin, Milwaukee
dspiewak@uwm.edu
Abstract
We present a functional approach to parsing unrestricted context-
free grammars based on Brzozowski’s derivative of regular expres-
sions. If we consider context-free grammars as recursive regular ex-
pressions, Brzozowski’s equational theory extends without modifi-
cation to context-free grammars (and it generalizes to parser combi-
nators). The supporting actors in this story are three concepts famil-
iar to functional programmers—laziness, memoization and fixed
points; these allow Brzozowski’s original equations to be translit-
erated into purely functional code in about 30 lines spread over
three functions.
Yet, this almost impossibly brief implementation has a draw-
back: its performance is sour—in both theory and practice. The
culprit? Each derivative can double the size of a grammar, and with
it, the cost of the next derivative.
Fortunately, much of the new structure inflicted by the derivative
is either dead on arrival, or it dies after the very next derivative.
To eliminate it, we once again exploit laziness and memoization
The derivative of regular expressions [1], if gently tempered
with laziness, memoization and fixed points, acts immediately
as a pure, functional technique for generating parse forests from
arbitrary context-free grammars. Despite—even because of—its
simplicity, the derivative transparently handles ambiguity, left-
recursion, right-recursion, ill-founded recursion or any combina-
tion thereof.
1.1 Outline
• After a review of formal languages, we introduce Brzozowski’s
derivative for regular languages. A brief implementation high-
lights its rugged elegance.
• As our implementation of the derivative engages context-free
languages, non-termination emerges as a problem.
• Three small, surgical modifications to the implementation (but
not the theory)—laziness, memoization and fixed points—
guarantee termination. Termination means the derivative can
blog.klipse.tech/clojure/2016/10/02/parsing-with-derivatives-regular.html
Writing a spec should enable automatic:
• Validation
• Error reporting
• Destructuring
• Instrumentation
• Test-data generation
• Generative test generation
*http://clojure.org/about/spec
“Composition is about
decomposing.”
— E. Normand
The code base
• ~15k loc
• ETL
• Risk-hedging
• Demand-responsive pricing
• Packing & routing
• Internal BI tools
• …
Validation
• API boundaries
• Structured errors
• Fail fast = more context
• nil punning
• Multiple airities
Friendlier error messages
• Pluggable explanations via s/*explain-out*
• Capture common mistakes
• Provide hints
• Limitations
• One explainer function for all
• Don’t know which spec (only what went wrong)
Destructuring
• Pull apart and name
• Patterns
• case (dispatch on tag)
• core.match
• Separate data description and transformation
Two schools of
thinking
System paradigmLanguage paradigm
infoq.com/presentations/Mixin-based-Inheritance
realworldclojure.com/the-system-paradigm
The system paradigm
1. Nibble at the problem from different directions
2. Compose partial solutions into the final solution
Data macros
• Recursive transformations into canonical form
• s/conformer
• Do more without code macros
* juxt.pro/blog/posts/data-macros.html
Generative testing
• Limitations
• sequences with internal structure (time series
etc.)
• generic higher-order functions (e.g. map)
• Uncovers numerical instabilities
• s/exercise for mocking
Queryable data descriptions
• s/registry, s/form
• Build a graph
• No inline docs :(
Case study: autogenerating materialised views
Kafka
Materialised
views
Events
External data
Automatic view generation
• Event & attribute ontology
• Manual (via spec)
• Inferred
• Statistical analysis (seasonality
detection, outlier removal, …)
Onyx Onyx
Onyx
Simple first,
then Easy
Going forward
Questions
@sbelak
simon@goopti.com
My favourites
• Data macros
• Destructuring
• Queryable data descriptions
• Structured errors
• clojure.org/about/spec
• matt.might.net/papers/might2011derivatives.pdf
• infoq.com/presentations/Mixin-based-Inheritance
• realworldclojure.com/the-system-paradigm
• juxt.pro/blog/posts/data-macros.html
• blog.klipse.tech/clojure/2016/10/02/parsing-with-derivatives-
regular.html
• indiegogo.com/projects/typed-clojure-clojure-spec-auto-
annotations#/
• github.com/arohner/spectrum

More Related Content

What's hot

Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - TalkMatthias Noback
 
Service abstractions - Part 1: Queries
Service abstractions - Part 1: QueriesService abstractions - Part 1: Queries
Service abstractions - Part 1: QueriesMatthias Noback
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2WebMatthias Noback
 
Layers, ports and adapters
Layers, ports and adaptersLayers, ports and adapters
Layers, ports and adaptersMatthias Noback
 
A testing strategy for hexagonal applications
A testing strategy for hexagonal applicationsA testing strategy for hexagonal applications
A testing strategy for hexagonal applicationsMatthias Noback
 
Dynamic C# and a New World of Possibilities
Dynamic C# and a New World of PossibilitiesDynamic C# and a New World of Possibilities
Dynamic C# and a New World of PossibilitiesChicago ALT.NET
 
Introduction to Functional Programming and Clojure
Introduction to Functional Programming and ClojureIntroduction to Functional Programming and Clojure
Introduction to Functional Programming and ClojureSoumendra Daas
 
A Novel Visualization of Biblical Texts Aligned at the Word-Level
A Novel Visualization of Biblical Texts Aligned at the Word-LevelA Novel Visualization of Biblical Texts Aligned at the Word-Level
A Novel Visualization of Biblical Texts Aligned at the Word-LevelAndrewZulker
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testingKnoldus Inc.
 
Natural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine TranslationNatural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine Translationivaderivader
 
Some Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and PrinciplesSome Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and Principlesitsarsalan
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with XtextGlobalLogic Ukraine
 

What's hot (15)

Advanced web application architecture - Talk
Advanced web application architecture - TalkAdvanced web application architecture - Talk
Advanced web application architecture - Talk
 
Service abstractions - Part 1: Queries
Service abstractions - Part 1: QueriesService abstractions - Part 1: Queries
Service abstractions - Part 1: Queries
 
Advanced web application architecture Way2Web
Advanced web application architecture Way2WebAdvanced web application architecture Way2Web
Advanced web application architecture Way2Web
 
Layers, ports and adapters
Layers, ports and adaptersLayers, ports and adapters
Layers, ports and adapters
 
A testing strategy for hexagonal applications
A testing strategy for hexagonal applicationsA testing strategy for hexagonal applications
A testing strategy for hexagonal applications
 
Dynamic C# and a New World of Possibilities
Dynamic C# and a New World of PossibilitiesDynamic C# and a New World of Possibilities
Dynamic C# and a New World of Possibilities
 
Introduction to Functional Programming and Clojure
Introduction to Functional Programming and ClojureIntroduction to Functional Programming and Clojure
Introduction to Functional Programming and Clojure
 
ANTLR4 in depth
ANTLR4 in depthANTLR4 in depth
ANTLR4 in depth
 
A Novel Visualization of Biblical Texts Aligned at the Word-Level
A Novel Visualization of Biblical Texts Aligned at the Word-LevelA Novel Visualization of Biblical Texts Aligned at the Word-Level
A Novel Visualization of Biblical Texts Aligned at the Word-Level
 
Introdução à Elixir
Introdução à ElixirIntrodução à Elixir
Introdução à Elixir
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
ANTLR4 and its testing
ANTLR4 and its testingANTLR4 and its testing
ANTLR4 and its testing
 
Natural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine TranslationNatural Language to Visualization by Neural Machine Translation
Natural Language to Visualization by Neural Machine Translation
 
Some Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and PrinciplesSome Cool Design Patterns, Practices, and Principles
Some Cool Design Patterns, Practices, and Principles
 
Building Your Own DSL with Xtext
Building Your Own DSL with XtextBuilding Your Own DSL with Xtext
Building Your Own DSL with Xtext
 

Viewers also liked

Odkrivanje segmentov iz podatkov
Odkrivanje segmentov iz podatkovOdkrivanje segmentov iz podatkov
Odkrivanje segmentov iz podatkovSimon Belak
 
Turn to datadriven: the first 6 months
Turn to datadriven: the first 6 monthsTurn to datadriven: the first 6 months
Turn to datadriven: the first 6 monthsSimon Belak
 
O Filozofih In Programih
O Filozofih In ProgramihO Filozofih In Programih
O Filozofih In ProgramihSimon Belak
 
The time is out of joint: O cursed spite, / That ever I was born to set it ri...
The time is out of joint: O cursed spite, / That ever I was born to set it ri...The time is out of joint: O cursed spite, / That ever I was born to set it ri...
The time is out of joint: O cursed spite, / That ever I was born to set it ri...Simon Belak
 
Doing data science with Clojure
Doing data science with ClojureDoing data science with Clojure
Doing data science with ClojureSimon Belak
 
Predicting the future with goopti
Predicting the future with gooptiPredicting the future with goopti
Predicting the future with gooptiSimon Belak
 
Napadi na algoritme za strojno učenje
Napadi na algoritme za strojno učenjeNapadi na algoritme za strojno učenje
Napadi na algoritme za strojno učenjeSimon Belak
 
Turn to data-driven: the first 6 months, Simon Belak
Turn to data-driven: the first 6 months, Simon BelakTurn to data-driven: the first 6 months, Simon Belak
Turn to data-driven: the first 6 months, Simon BelakRed Orbit digital marketing
 
Living with-spec
Living with-specLiving with-spec
Living with-specSimon Belak
 
Using Onyx in anger
Using Onyx in angerUsing Onyx in anger
Using Onyx in angerSimon Belak
 

Viewers also liked (13)

Spec + onyx
Spec + onyxSpec + onyx
Spec + onyx
 
Odkrivanje segmentov iz podatkov
Odkrivanje segmentov iz podatkovOdkrivanje segmentov iz podatkov
Odkrivanje segmentov iz podatkov
 
Turn to datadriven: the first 6 months
Turn to datadriven: the first 6 monthsTurn to datadriven: the first 6 months
Turn to datadriven: the first 6 months
 
O Filozofih In Programih
O Filozofih In ProgramihO Filozofih In Programih
O Filozofih In Programih
 
inOrbit 2015: odkrivanje segmentov iz podatkov
inOrbit 2015: odkrivanje segmentov iz podatkovinOrbit 2015: odkrivanje segmentov iz podatkov
inOrbit 2015: odkrivanje segmentov iz podatkov
 
The time is out of joint: O cursed spite, / That ever I was born to set it ri...
The time is out of joint: O cursed spite, / That ever I was born to set it ri...The time is out of joint: O cursed spite, / That ever I was born to set it ri...
The time is out of joint: O cursed spite, / That ever I was born to set it ri...
 
Dao of lisp
Dao of lispDao of lisp
Dao of lisp
 
Doing data science with Clojure
Doing data science with ClojureDoing data science with Clojure
Doing data science with Clojure
 
Predicting the future with goopti
Predicting the future with gooptiPredicting the future with goopti
Predicting the future with goopti
 
Napadi na algoritme za strojno učenje
Napadi na algoritme za strojno učenjeNapadi na algoritme za strojno učenje
Napadi na algoritme za strojno učenje
 
Turn to data-driven: the first 6 months, Simon Belak
Turn to data-driven: the first 6 months, Simon BelakTurn to data-driven: the first 6 months, Simon Belak
Turn to data-driven: the first 6 months, Simon Belak
 
Living with-spec
Living with-specLiving with-spec
Living with-spec
 
Using Onyx in anger
Using Onyx in angerUsing Onyx in anger
Using Onyx in anger
 

Similar to Living with-spec

Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSimon Belak
 
Wcre2009 bettenburg
Wcre2009 bettenburgWcre2009 bettenburg
Wcre2009 bettenburgSAIL_QU
 
Practical functional programming in JavaScript for the non-mathematician
Practical functional programming in JavaScript for the non-mathematicianPractical functional programming in JavaScript for the non-mathematician
Practical functional programming in JavaScript for the non-mathematicianIan Thomas
 
Semantic Interoperability - grafi della conoscenza
Semantic Interoperability - grafi della conoscenzaSemantic Interoperability - grafi della conoscenza
Semantic Interoperability - grafi della conoscenzaGiorgia Lodi
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaopenseesdays
 
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018Sri Ambati
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 
Parallel Computing 2007: Overview
Parallel Computing 2007: OverviewParallel Computing 2007: Overview
Parallel Computing 2007: OverviewGeoffrey Fox
 
OSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityOSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityGleicon Moraes
 
Computational Approaches to Systems Biology
Computational Approaches to Systems BiologyComputational Approaches to Systems Biology
Computational Approaches to Systems BiologyMike Hucka
 
A Case Study Of A Reusable Component Collection
A Case Study Of A Reusable Component CollectionA Case Study Of A Reusable Component Collection
A Case Study Of A Reusable Component CollectionJennifer Strong
 
Software_engineering.pptx
Software_engineering.pptxSoftware_engineering.pptx
Software_engineering.pptxjohn6938
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallJohn Mulhall
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave ImplicitMartin Odersky
 

Similar to Living with-spec (20)

Spec: a lisp-flavoured type system
Spec: a lisp-flavoured type systemSpec: a lisp-flavoured type system
Spec: a lisp-flavoured type system
 
Wcre2009 bettenburg
Wcre2009 bettenburgWcre2009 bettenburg
Wcre2009 bettenburg
 
Practical functional programming in JavaScript for the non-mathematician
Practical functional programming in JavaScript for the non-mathematicianPractical functional programming in JavaScript for the non-mathematician
Practical functional programming in JavaScript for the non-mathematician
 
Six of the Best
Six of the BestSix of the Best
Six of the Best
 
Semantic Interoperability - grafi della conoscenza
Semantic Interoperability - grafi della conoscenzaSemantic Interoperability - grafi della conoscenza
Semantic Interoperability - grafi della conoscenza
 
Symbolic Execution And KLEE
Symbolic Execution And KLEESymbolic Execution And KLEE
Symbolic Execution And KLEE
 
Introduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKennaIntroduction to OpenSees by Frank McKenna
Introduction to OpenSees by Frank McKenna
 
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018
Machine Learning Interpretability - Mateusz Dymczyk - H2O AI World London 2018
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 
Parallel Computing 2007: Overview
Parallel Computing 2007: OverviewParallel Computing 2007: Overview
Parallel Computing 2007: Overview
 
OSCon - Performance vs Scalability
OSCon - Performance vs ScalabilityOSCon - Performance vs Scalability
OSCon - Performance vs Scalability
 
What's in a Name?
What's in a Name?What's in a Name?
What's in a Name?
 
Computational Approaches to Systems Biology
Computational Approaches to Systems BiologyComputational Approaches to Systems Biology
Computational Approaches to Systems Biology
 
A Case Study Of A Reusable Component Collection
A Case Study Of A Reusable Component CollectionA Case Study Of A Reusable Component Collection
A Case Study Of A Reusable Component Collection
 
Rust presentation convergeconf
Rust presentation convergeconfRust presentation convergeconf
Rust presentation convergeconf
 
Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)
 
Software_engineering.pptx
Software_engineering.pptxSoftware_engineering.pptx
Software_engineering.pptx
 
Oop
OopOop
Oop
 
Introduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John MulhallIntroduction to Software - Coder Forge - John Mulhall
Introduction to Software - Coder Forge - John Mulhall
 
What To Leave Implicit
What To Leave ImplicitWhat To Leave Implicit
What To Leave Implicit
 

More from Simon Belak

Tools for building the future
Tools for building the futureTools for building the future
Tools for building the futureSimon Belak
 
Doing data science with clojure
Doing data science with clojureDoing data science with clojure
Doing data science with clojureSimon Belak
 
Exploratory analysis
Exploratory analysisExploratory analysis
Exploratory analysisSimon Belak
 
Levelling up your data infrastructure
Levelling up your data infrastructureLevelling up your data infrastructure
Levelling up your data infrastructureSimon Belak
 
The subtle art of recommendation
The subtle art of recommendationThe subtle art of recommendation
The subtle art of recommendationSimon Belak
 
Metabase Ljubljana Meetup #2
Metabase Ljubljana Meetup #2Metabase Ljubljana Meetup #2
Metabase Ljubljana Meetup #2Simon Belak
 
Metabase lj meetup
Metabase lj meetupMetabase lj meetup
Metabase lj meetupSimon Belak
 
Sketch algorithms
Sketch algorithmsSketch algorithms
Sketch algorithmsSimon Belak
 
Transducing for fun and profit
Transducing for fun and profitTransducing for fun and profit
Transducing for fun and profitSimon Belak
 
Your metrics are wrong
Your metrics are wrongYour metrics are wrong
Your metrics are wrongSimon Belak
 
Writing smart contracts the sane way
Writing smart contracts the sane wayWriting smart contracts the sane way
Writing smart contracts the sane waySimon Belak
 
Online statistical analysis using transducers and sketch algorithms
Online statistical analysis using transducers and sketch algorithmsOnline statistical analysis using transducers and sketch algorithms
Online statistical analysis using transducers and sketch algorithmsSimon Belak
 
Save the princess
Save the princessSave the princess
Save the princessSimon Belak
 
Data driven going to market strategy
Data driven going to market strategyData driven going to market strategy
Data driven going to market strategySimon Belak
 
A data layer in clojure
A data layer in clojureA data layer in clojure
A data layer in clojureSimon Belak
 
Statisics for hackers
Statisics for hackersStatisics for hackers
Statisics for hackersSimon Belak
 
The data driven startup
The data driven startupThe data driven startup
The data driven startupSimon Belak
 

More from Simon Belak (19)

Tools for building the future
Tools for building the futureTools for building the future
Tools for building the future
 
Doing data science with clojure
Doing data science with clojureDoing data science with clojure
Doing data science with clojure
 
Exploratory analysis
Exploratory analysisExploratory analysis
Exploratory analysis
 
Levelling up your data infrastructure
Levelling up your data infrastructureLevelling up your data infrastructure
Levelling up your data infrastructure
 
The subtle art of recommendation
The subtle art of recommendationThe subtle art of recommendation
The subtle art of recommendation
 
Metabase Ljubljana Meetup #2
Metabase Ljubljana Meetup #2Metabase Ljubljana Meetup #2
Metabase Ljubljana Meetup #2
 
Metabase lj meetup
Metabase lj meetupMetabase lj meetup
Metabase lj meetup
 
Sketch algorithms
Sketch algorithmsSketch algorithms
Sketch algorithms
 
Transducing for fun and profit
Transducing for fun and profitTransducing for fun and profit
Transducing for fun and profit
 
Your metrics are wrong
Your metrics are wrongYour metrics are wrong
Your metrics are wrong
 
Writing smart contracts the sane way
Writing smart contracts the sane wayWriting smart contracts the sane way
Writing smart contracts the sane way
 
Online statistical analysis using transducers and sketch algorithms
Online statistical analysis using transducers and sketch algorithmsOnline statistical analysis using transducers and sketch algorithms
Online statistical analysis using transducers and sketch algorithms
 
Save the princess
Save the princessSave the princess
Save the princess
 
Data driven going to market strategy
Data driven going to market strategyData driven going to market strategy
Data driven going to market strategy
 
A data layer in clojure
A data layer in clojureA data layer in clojure
A data layer in clojure
 
The log
The logThe log
The log
 
Statisics for hackers
Statisics for hackersStatisics for hackers
Statisics for hackers
 
The data driven startup
The data driven startupThe data driven startup
The data driven startup
 
Investor story
Investor storyInvestor story
Investor story
 

Recently uploaded

Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxolyaivanovalion
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 

Recently uploaded (20)

Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Ravak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptxRavak dropshipping via API with DroFx.pptx
Ravak dropshipping via API with DroFx.pptx
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 

Living with-spec

  • 2. Parsing with Derivatives A Functional Pearl Matthew Might David Darais University of Utah might@cs.utah.edu, david.darais@gmail.com Daniel Spiewak University of Wisconsin, Milwaukee dspiewak@uwm.edu Abstract We present a functional approach to parsing unrestricted context- free grammars based on Brzozowski’s derivative of regular expres- sions. If we consider context-free grammars as recursive regular ex- pressions, Brzozowski’s equational theory extends without modifi- cation to context-free grammars (and it generalizes to parser combi- nators). The supporting actors in this story are three concepts famil- iar to functional programmers—laziness, memoization and fixed points; these allow Brzozowski’s original equations to be translit- erated into purely functional code in about 30 lines spread over three functions. Yet, this almost impossibly brief implementation has a draw- back: its performance is sour—in both theory and practice. The culprit? Each derivative can double the size of a grammar, and with it, the cost of the next derivative. Fortunately, much of the new structure inflicted by the derivative is either dead on arrival, or it dies after the very next derivative. To eliminate it, we once again exploit laziness and memoization The derivative of regular expressions [1], if gently tempered with laziness, memoization and fixed points, acts immediately as a pure, functional technique for generating parse forests from arbitrary context-free grammars. Despite—even because of—its simplicity, the derivative transparently handles ambiguity, left- recursion, right-recursion, ill-founded recursion or any combina- tion thereof. 1.1 Outline • After a review of formal languages, we introduce Brzozowski’s derivative for regular languages. A brief implementation high- lights its rugged elegance. • As our implementation of the derivative engages context-free languages, non-termination emerges as a problem. • Three small, surgical modifications to the implementation (but not the theory)—laziness, memoization and fixed points— guarantee termination. Termination means the derivative can
  • 4. Writing a spec should enable automatic: • Validation • Error reporting • Destructuring • Instrumentation • Test-data generation • Generative test generation *http://clojure.org/about/spec
  • 6. The code base • ~15k loc • ETL • Risk-hedging • Demand-responsive pricing • Packing & routing • Internal BI tools • …
  • 7. Validation • API boundaries • Structured errors • Fail fast = more context • nil punning • Multiple airities
  • 8. Friendlier error messages • Pluggable explanations via s/*explain-out* • Capture common mistakes • Provide hints • Limitations • One explainer function for all • Don’t know which spec (only what went wrong)
  • 9. Destructuring • Pull apart and name • Patterns • case (dispatch on tag) • core.match • Separate data description and transformation
  • 12. The system paradigm 1. Nibble at the problem from different directions 2. Compose partial solutions into the final solution
  • 13. Data macros • Recursive transformations into canonical form • s/conformer • Do more without code macros * juxt.pro/blog/posts/data-macros.html
  • 14.
  • 15.
  • 16.
  • 17. Generative testing • Limitations • sequences with internal structure (time series etc.) • generic higher-order functions (e.g. map) • Uncovers numerical instabilities • s/exercise for mocking
  • 18. Queryable data descriptions • s/registry, s/form • Build a graph • No inline docs :(
  • 19. Case study: autogenerating materialised views Kafka Materialised views Events External data Automatic view generation • Event & attribute ontology • Manual (via spec) • Inferred • Statistical analysis (seasonality detection, outlier removal, …) Onyx Onyx Onyx
  • 21.
  • 24. My favourites • Data macros • Destructuring • Queryable data descriptions • Structured errors
  • 25. • clojure.org/about/spec • matt.might.net/papers/might2011derivatives.pdf • infoq.com/presentations/Mixin-based-Inheritance • realworldclojure.com/the-system-paradigm • juxt.pro/blog/posts/data-macros.html • blog.klipse.tech/clojure/2016/10/02/parsing-with-derivatives- regular.html • indiegogo.com/projects/typed-clojure-clojure-spec-auto- annotations#/ • github.com/arohner/spectrum