SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Static Guarantees for Macro
Bindings
Mitchell Wand
Presentation for Gnosys site visit
12/14/12
Why study macros?
   macros are a facility for lightweight
    compilers
   translate DSL into host language (Racket),
    then let Racket compiler work
   easy interoperation with host language, etc.
   most translation is on a per-s-expression
    basis
   Racket macro system has features that
    permit interaction between macros,
    optimizations, fancier syntax, etc.
Want: static reasoning about
hygiene
 Does the expansion of a macro obey its
  intended scoping rules?
 Does my-let act like let?
    ◦ Is id0 bound in body?
(define-syntax my-let
  (syntax-rules ()
    [(_ ((id0 val0) (id val) ...) body)
     ((lambda (id ...) body)
      val ...)]))
                              Answer: No
Didn't Dybvig solve this in 1993?
 No notion of "intended scoping rules"
 Dybvig's algorithm works out binding
  relationships dynamically.
 We want static guarantees.
Didn't the nominal logic guys
solve this?
 Nominal logic: Pitts, et al. 2000 or so, et seq.
 Logic for reasoning about names
 Much work about representing terms with
  binding. BUT:
 Aimed at theorem proving, not
  programming
 Generally involves data representations that
  carry their scoping rules with them:
    ◦ lambda-terms, not s-expressions.
    ◦ Macros must translate from s-expressions (or
      something like them) to lambda-terms (or
      something like them)
Our Starting Points (I)
   Ott: a specification language for binding
    patterns, like Ott (ICFP 2007, JFP 2010)
p ::=                 // patterns
                                 A primitive binder
| x                   binders = x
| { l1=p1,...,ln=pn } binders = binders(p1 ... pn)

                                A composite binder
t ::=                 // terms
| let p = t in t’ bind binders(p) in t’



                           Bind these variables in t
This doesn't solve the problem
   Ott has back-ends for
    ◦ Latex
    ◦ several theorem provers
   But it's not a general-purpose tool
Our Starting Points (II)
   Dave Herman's thesis (2010)
    ◦ took Ott-like specification language
    ◦ static checking for syntax-rules style macros
 Would reject my-let from slide 1.
 Goal: extend this to procedurally-defined
  macros (e.g. syntax-case)
Our Starting Points (III)
 Pottier's Functional Fresh ML (LICS 2007)
 A programming language based on
  nominal logic.
 His goal: programming with binders.
    ◦ functions map alpha-equivalent objects to
      alpha-equivalent objects
   Attractive semantics
    ◦ no hidden gensym (!)
Pottier's Result
   Theorem 1: Any function in Fresh ML
    either preserves alpha-equivalence or
    else faults     Dynamic! 
    ◦ careful language design, any bound variable
      that escapes its scope triggers a fault.

   Theorem 2: From any program in Fresh
    ML, we can derive a formula G s.t. if G is
    true, then the program never faults.
    Static!           Can use SMT prover
Does this solve the problem?
 No: his data still carries around its own
  binding information dynamically
 We need to manipulate plain old s-
  expressions (or something like them)
Our plan
 Adapt Pottier's system to use plain old s-
  expressions.
 Keep the binding information in types
  (static) rather than in the data (dynamic)
Progress [Work by Paul
Stansifer]
 Core language defined
 Static checks defined (extension of
  Pottier's)
 Now working on proofs of theorems
A Binding Specification
                                             We use positional
                                             notation for now
// input         0       1
Expr' = App' Expr Expr             bindings from Atom and
      | Lam' Atom Expr↓0           LetClauses are bound in
                                   Expr
      | Var' Atom
      | Let LetClauses Expr↓0
      | LetRec LetClauses↓0 Expr

                                       Atoms export themselves
LetClauses = LCNone
  | LCBind Atom Expr LetClauses ⇑0⊎2
             0       1       2
// output
Expr = App Expr Expr                   Export bindings from
                                       Atom and LetClauses
     | Lam Atom Expr↓0
    | Var Atom
Next Steps
 Interface to SMT prover (w/ Fabian
  Muehlenboeck)
 What adaptations are necessary to make
  these obligations acceptable to an SMT-
  style prover?
 Actually write some macros in this
  system.

Weitere ähnliche Inhalte

Was ist angesagt?

How to Learn Java Programming
How to Learn Java ProgrammingHow to Learn Java Programming
How to Learn Java ProgrammingJava2Blog
 
Macro discussion (owled 2010)
Macro discussion (owled 2010)Macro discussion (owled 2010)
Macro discussion (owled 2010)Chris Mungall
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - PolymorphismMudasir Qazi
 
Introduction to Transformers for NLP - Olga Petrova
Introduction to Transformers for NLP - Olga PetrovaIntroduction to Transformers for NLP - Olga Petrova
Introduction to Transformers for NLP - Olga PetrovaAlexey Grigorev
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Anil Bapat
 
Basics java programing
Basics java programingBasics java programing
Basics java programingDarshan Gohel
 
Clojure presentation
Clojure presentationClojure presentation
Clojure presentationedpaget
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers Arvind Devaraj
 
Thomas Wolf "Transfer learning in NLP"
Thomas Wolf "Transfer learning in NLP"Thomas Wolf "Transfer learning in NLP"
Thomas Wolf "Transfer learning in NLP"Fwdays
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Srimatre K
 
Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...
 Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De... Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...
Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...Ohsawa Goodfellow
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...cprogrammings
 
Finite state system or finite automata
Finite state system or finite automataFinite state system or finite automata
Finite state system or finite automataDr. ABHISHEK K PANDEY
 
論文輪読資料「Gated Feedback Recurrent Neural Networks」
論文輪読資料「Gated Feedback Recurrent Neural Networks」論文輪読資料「Gated Feedback Recurrent Neural Networks」
論文輪読資料「Gated Feedback Recurrent Neural Networks」kurotaki_weblab
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python Home
 

Was ist angesagt? (20)

How to Learn Java Programming
How to Learn Java ProgrammingHow to Learn Java Programming
How to Learn Java Programming
 
Macro discussion (owled 2010)
Macro discussion (owled 2010)Macro discussion (owled 2010)
Macro discussion (owled 2010)
 
OOP - Polymorphism
OOP - PolymorphismOOP - Polymorphism
OOP - Polymorphism
 
Introduction to Transformers for NLP - Olga Petrova
Introduction to Transformers for NLP - Olga PetrovaIntroduction to Transformers for NLP - Olga Petrova
Introduction to Transformers for NLP - Olga Petrova
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
Basics java programing
Basics java programingBasics java programing
Basics java programing
 
Clojure presentation
Clojure presentationClojure presentation
Clojure presentation
 
NLP using transformers
NLP using transformers NLP using transformers
NLP using transformers
 
polymorphism
polymorphism polymorphism
polymorphism
 
Thomas Wolf "Transfer learning in NLP"
Thomas Wolf "Transfer learning in NLP"Thomas Wolf "Transfer learning in NLP"
Thomas Wolf "Transfer learning in NLP"
 
Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4Formal Languages and Automata Theory unit 4
Formal Languages and Automata Theory unit 4
 
Introduction to Transformer Model
Introduction to Transformer ModelIntroduction to Transformer Model
Introduction to Transformer Model
 
Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...
 Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De... Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...
Semi-Supervised Autoencoders for Predicting Sentiment Distributions(第 5 回 De...
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
05 dataflow
05 dataflow05 dataflow
05 dataflow
 
Finite state system or finite automata
Finite state system or finite automataFinite state system or finite automata
Finite state system or finite automata
 
args_types
args_typesargs_types
args_types
 
論文輪読資料「Gated Feedback Recurrent Neural Networks」
論文輪読資料「Gated Feedback Recurrent Neural Networks」論文輪読資料「Gated Feedback Recurrent Neural Networks」
論文輪読資料「Gated Feedback Recurrent Neural Networks」
 
Polymorphism in Python
Polymorphism in Python Polymorphism in Python
Polymorphism in Python
 

Ähnlich wie Site visit presentation 2012 12 14

The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsMarkus Voelter
 
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...Codemotion
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
Resg ph d_seminar2010_germansibay
Resg ph d_seminar2010_germansibayResg ph d_seminar2010_germansibay
Resg ph d_seminar2010_germansibayRESGWorkshop
 
An Introduction to Pre-training General Language Representations
An Introduction to Pre-training General Language RepresentationsAn Introduction to Pre-training General Language Representations
An Introduction to Pre-training General Language Representationszperjaccico
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Raffi Khatchadourian
 
Attention mechanisms with tensorflow
Attention mechanisms with tensorflowAttention mechanisms with tensorflow
Attention mechanisms with tensorflowKeon Kim
 
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...Sergey Staroletov
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part維佋 唐
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency ConstructsTed Leung
 
Word embeddings
Word embeddingsWord embeddings
Word embeddingsShruti kar
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questionsakila viji
 
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...Learning to Generate Pseudo-code from Source Code using Statistical Machine T...
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...Yusuke Oda
 
用R语言做曲线拟合
用R语言做曲线拟合用R语言做曲线拟合
用R语言做曲线拟合Wenxiang Zhu
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Garth Gilmour
 
Dataworkz odsc london 2018
Dataworkz odsc london 2018Dataworkz odsc london 2018
Dataworkz odsc london 2018Olaf de Leeuw
 
05-transformers.pdf
05-transformers.pdf05-transformers.pdf
05-transformers.pdfChaoYang81
 

Ähnlich wie Site visit presentation 2012 12 14 (20)

The future of DSLs - functions and formal methods
The future of DSLs - functions and formal methodsThe future of DSLs - functions and formal methods
The future of DSLs - functions and formal methods
 
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...
Deep Learning for Machine Translation: a paradigm shift - Alberto Massidda - ...
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
Resg ph d_seminar2010_germansibay
Resg ph d_seminar2010_germansibayResg ph d_seminar2010_germansibay
Resg ph d_seminar2010_germansibay
 
An Introduction to Pre-training General Language Representations
An Introduction to Pre-training General Language RepresentationsAn Introduction to Pre-training General Language Representations
An Introduction to Pre-training General Language Representations
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
 
IN4308 1
IN4308 1IN4308 1
IN4308 1
 
Attention mechanisms with tensorflow
Attention mechanisms with tensorflowAttention mechanisms with tensorflow
Attention mechanisms with tensorflow
 
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
MODEL OF A PROGRAM AS MULTITHREADED STOCHASTIC AUTOMATON AND ITS EQUIVALENT T...
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part
 
A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Word embeddings
Word embeddingsWord embeddings
Word embeddings
 
Compiler design important questions
Compiler design   important questionsCompiler design   important questions
Compiler design important questions
 
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...Learning to Generate Pseudo-code from Source Code using Statistical Machine T...
Learning to Generate Pseudo-code from Source Code using Statistical Machine T...
 
用R语言做曲线拟合
用R语言做曲线拟合用R语言做曲线拟合
用R语言做曲线拟合
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)Does Java Have a Future After Version 8? (Belfast JUG April 2014)
Does Java Have a Future After Version 8? (Belfast JUG April 2014)
 
Dataworkz odsc london 2018
Dataworkz odsc london 2018Dataworkz odsc london 2018
Dataworkz odsc london 2018
 
Matlab-3.pptx
Matlab-3.pptxMatlab-3.pptx
Matlab-3.pptx
 
05-transformers.pdf
05-transformers.pdf05-transformers.pdf
05-transformers.pdf
 

Mehr von Mitchell Wand

Week 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsWeek 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsMitchell Wand
 
Week 03 Lesson 02 recursive data definitions everywhere
Week 03 Lesson 02 recursive data definitions everywhereWeek 03 Lesson 02 recursive data definitions everywhere
Week 03 Lesson 02 recursive data definitions everywhereMitchell Wand
 
Lesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemLesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemMitchell Wand
 
Lesson 03 Arbitrarily Recursive Data Definitions
Lesson 03 Arbitrarily  Recursive Data DefinitionsLesson 03 Arbitrarily  Recursive Data Definitions
Lesson 03 Arbitrarily Recursive Data DefinitionsMitchell Wand
 
Lesson 04 Lists Of Lists Of Lists
Lesson 04 Lists Of Lists Of ListsLesson 04 Lists Of Lists Of Lists
Lesson 04 Lists Of Lists Of ListsMitchell Wand
 
Lesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresLesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresMitchell Wand
 

Mehr von Mitchell Wand (7)

My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
Week 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data DefinitionsWeek 02 Lesson 02 Recursive Data Definitions
Week 02 Lesson 02 Recursive Data Definitions
 
Week 03 Lesson 02 recursive data definitions everywhere
Week 03 Lesson 02 recursive data definitions everywhereWeek 03 Lesson 02 recursive data definitions everywhere
Week 03 Lesson 02 recursive data definitions everywhere
 
Lesson 01 A Warmup Problem
Lesson 01 A Warmup ProblemLesson 01 A Warmup Problem
Lesson 01 A Warmup Problem
 
Lesson 03 Arbitrarily Recursive Data Definitions
Lesson 03 Arbitrarily  Recursive Data DefinitionsLesson 03 Arbitrarily  Recursive Data Definitions
Lesson 03 Arbitrarily Recursive Data Definitions
 
Lesson 04 Lists Of Lists Of Lists
Lesson 04 Lists Of Lists Of ListsLesson 04 Lists Of Lists Of Lists
Lesson 04 Lists Of Lists Of Lists
 
Lesson 05 Analyzing Structures
Lesson 05 Analyzing StructuresLesson 05 Analyzing Structures
Lesson 05 Analyzing Structures
 

Site visit presentation 2012 12 14

  • 1. Static Guarantees for Macro Bindings Mitchell Wand Presentation for Gnosys site visit 12/14/12
  • 2. Why study macros?  macros are a facility for lightweight compilers  translate DSL into host language (Racket), then let Racket compiler work  easy interoperation with host language, etc.  most translation is on a per-s-expression basis  Racket macro system has features that permit interaction between macros, optimizations, fancier syntax, etc.
  • 3. Want: static reasoning about hygiene  Does the expansion of a macro obey its intended scoping rules?  Does my-let act like let? ◦ Is id0 bound in body? (define-syntax my-let (syntax-rules () [(_ ((id0 val0) (id val) ...) body) ((lambda (id ...) body) val ...)])) Answer: No
  • 4. Didn't Dybvig solve this in 1993?  No notion of "intended scoping rules"  Dybvig's algorithm works out binding relationships dynamically.  We want static guarantees.
  • 5. Didn't the nominal logic guys solve this?  Nominal logic: Pitts, et al. 2000 or so, et seq.  Logic for reasoning about names  Much work about representing terms with binding. BUT:  Aimed at theorem proving, not programming  Generally involves data representations that carry their scoping rules with them: ◦ lambda-terms, not s-expressions. ◦ Macros must translate from s-expressions (or something like them) to lambda-terms (or something like them)
  • 6. Our Starting Points (I)  Ott: a specification language for binding patterns, like Ott (ICFP 2007, JFP 2010) p ::= // patterns A primitive binder | x binders = x | { l1=p1,...,ln=pn } binders = binders(p1 ... pn) A composite binder t ::= // terms | let p = t in t’ bind binders(p) in t’ Bind these variables in t
  • 7. This doesn't solve the problem  Ott has back-ends for ◦ Latex ◦ several theorem provers  But it's not a general-purpose tool
  • 8. Our Starting Points (II)  Dave Herman's thesis (2010) ◦ took Ott-like specification language ◦ static checking for syntax-rules style macros  Would reject my-let from slide 1.  Goal: extend this to procedurally-defined macros (e.g. syntax-case)
  • 9. Our Starting Points (III)  Pottier's Functional Fresh ML (LICS 2007)  A programming language based on nominal logic.  His goal: programming with binders. ◦ functions map alpha-equivalent objects to alpha-equivalent objects  Attractive semantics ◦ no hidden gensym (!)
  • 10. Pottier's Result  Theorem 1: Any function in Fresh ML either preserves alpha-equivalence or else faults Dynamic!  ◦ careful language design, any bound variable that escapes its scope triggers a fault.  Theorem 2: From any program in Fresh ML, we can derive a formula G s.t. if G is true, then the program never faults. Static!  Can use SMT prover
  • 11. Does this solve the problem?  No: his data still carries around its own binding information dynamically  We need to manipulate plain old s- expressions (or something like them)
  • 12. Our plan  Adapt Pottier's system to use plain old s- expressions.  Keep the binding information in types (static) rather than in the data (dynamic)
  • 13. Progress [Work by Paul Stansifer]  Core language defined  Static checks defined (extension of Pottier's)  Now working on proofs of theorems
  • 14. A Binding Specification We use positional notation for now // input 0 1 Expr' = App' Expr Expr bindings from Atom and | Lam' Atom Expr↓0 LetClauses are bound in Expr | Var' Atom | Let LetClauses Expr↓0 | LetRec LetClauses↓0 Expr Atoms export themselves LetClauses = LCNone | LCBind Atom Expr LetClauses ⇑0⊎2 0 1 2 // output Expr = App Expr Expr Export bindings from Atom and LetClauses | Lam Atom Expr↓0 | Var Atom
  • 15. Next Steps  Interface to SMT prover (w/ Fabian Muehlenboeck)  What adaptations are necessary to make these obligations acceptable to an SMT- style prover?  Actually write some macros in this system.