30
Language and Ontology Shriram Krishnamurthi Yan-David Erlich Matthias Felleisen Rice University

Language and Ontology

  • Upload
    wauna

  • View
    46

  • Download
    2

Embed Size (px)

DESCRIPTION

Language and Ontology. Shriram Krishnamurthi Yan-David Erlich Matthias Felleisen Rice University. Language and Perception. Different programming styles influence the way we think about the world Therefore, programmers want to extend their languages to suit their problem domains - PowerPoint PPT Presentation

Citation preview

Page 1: Language and Ontology

Language and Ontology

Shriram KrishnamurthiYan-David Erlich

Matthias FelleisenRice University

Page 2: Language and Ontology

Language and PerceptionDifferent programming styles

influence the way we think about the world

Therefore, programmers want to extend their languages to suit their problem domains

Consequence: programmers define new languages all the time!

Page 3: Language and Ontology

Adaptive Programming:Overview

B u s

B u s L is t

P erson

P erson L is t

B u sS top

B u s S top L is t

B u sR ou te

Lieberherr, et al

Page 4: Language and Ontology

Adaptive Programming:Traversals

Traversal:

from BusRouteto Personthrough BusStop

B u s

B u sL is t

P erson

P erson L is t

B u sS top

B u sS top L is t

B u sR ou te

Page 5: Language and Ontology

Software Patterns:Overview

Concrete versions of design patternsAllow high-level descriptions of

creational, behavioral and structural properties

Map pattern instances to code

(Definition and mapping should respect the inductive structure of patterns)

Gamma, Helm, Johnson,Vlissides, and others

Page 6: Language and Ontology

Software Patterns:Example

Adapter Pattern

+ =Adapter

Page 7: Language and Ontology

Software Patterns +Adaptive Programming

Behaviors are described by the Visitor Pattern, but it has lots of syntactic overheadVisitor BusWaiterVisitor { BusRoute -> … BusStop -> … Person -> …}

Page 8: Language and Ontology

Scientific Computation:Matrices Overview

Implementation uses C++ templatesTwo languages are involved:configuration (extensional)

element type (float, complex, …) shape (upper triangular, symmetric, …)

implementation specification (intensional) bounds checked (yes, no) optimize for (speed, size)

Czarnecki, Eisenecker, et al

Page 9: Language and Ontology

Summary

Examples of the growing influence of domain-specific languages (DSLs)

DLSs are a way to institutionalize knowledge and make it common to all the programmers in an organization/domain

Some DSLs are created afresh; many leverage existing languages

Page 10: Language and Ontology

Are DSLs APIs?

begin_scope ();………end_scope ();

create_scoped_variable (“x”);…access_scoped_variable (“x”);

(This is a terrible language!)Similar examples in COM, etc

Page 11: Language and Ontology

Typical NeedsNew binding formsDifferent orders of evaluation

(applicative vs normal, right-to-left, etc)Domain-specific notations, conventions

Programmers use libraries because that’s all they have available!

Page 12: Language and Ontology

RoadmapNeeds a combination of support from the programming language and environment

Easy and powerful definitions Tight integration of language extensionsPreservation of language abstractionsPowerful implementation model

Page 13: Language and Ontology

Adaptive Programming:Recap

Visitor BusWaiterVisitor {

BusRoute -> … BusStop -> … Person -> …}

B u s

B u sL is t

P erson

P erson L is t

B u sS top

B u sS top L is t

B u sR ou te

Page 14: Language and Ontology

Tool Support forAdaptive Programming

Combining these specifications:

The adaptive programming tool does not know about our pattern extensions

Result: users must choose between DSLsSometimes, there is no ordering of DSLs

Page 15: Language and Ontology

Requirement:Tight Integration

External tools cannot be composedExternal tools may provide poor

debugging supportIntegrated tools may require the

environment to be re-built for every addition or change

Important consideration:Easy prototyping

Page 16: Language and Ontology

The Middle Ground

Start with macro systems a la Scheme

A macro system is a rewriting engine that works on a term structured syntax

The macro language is embedded into a host language

Multiple extensions can co-exist

Page 17: Language and Ontology

Definition Facility

(define-macro Adapter (rewrite (_ <aN> adapts <aT> to <dI> as <aV> (fields <fd> …) (methods <md> …)) (as (class <aN> implements <dI> (fields (<aT> <aV>) <fd> …) (methods <md> …))))

Page 18: Language and Ontology

Macros as Transformers

aN

aT

d I

aV

m d

m eth od s

fd

fie ld s

A d ap te r

aN

d I

aT aV

fd

fie ld sm d

m eth od s

c lass

Page 19: Language and Ontology

Requirement:Preserve Abstractions

Embedding languages would not be effective if the programmer did not get information in terms of what they wrote

(Information = type errors, programslices, value flow graphs, etc)

Page 20: Language and Ontology

Why This MattersMultiplicationExpression<class LazyBinaryExpression<class AdditionExpression<class MatrixICCL::Matrix<class

MatrixICCL::BoundsChecker<class MatrixICCL::ArrFormat<class MatrixICCL::StatExt<struct MatrixDSL::int_number<int,7>,struct MatrixDSL::int_number<int,7>>,class MatrixICCL::Rect<class MatrixICCL::StatExt<struct MatrixDSL::int_number<int,7>,struct MatrixDSL::int_number<int,7>>>,class MatrixICCL::Dyn2DCContainer<class MATRIX_ASSEMBLE_COMPONENTS<class MATRIX_DSL_ASSIGN_DEFAULTS<class MATRIX_DSL_PARSER<struct MatrixDSL::matrix<int,struct MatrixDSL::structure<struct MatrixDSL::rect<struct MatrixDSL::stat_val<struct MatrixDSL::int_number<int,7>>,struct MatrixDSL::stat_val<struct MatrixDSL::int_number<int,7>>,struct MatrixDSL::unspecified_DSL_feature>,struct MatrixDSL::dense<struct MatrixDSL::unspecified_DSL_feature>,struct MatrixDSL::dyn<struct MatrixDSL::unspecified_DSL_feature>>,struct MatrixDSL::speed<struct MatrixDSL::unspecified_DSL_feature>,struct MatrixDSL::unspecified_DSL_feature,struct MatrixDSL::unspecified_DSL_feature,struct MatrixDSL::unspecified_DSL_feature,struct MatrixDSL::unspecified_DSL_feature>>::DSLConfig>::DSLConfig>>>>>,class MatrixICCL::Matrix<class MatrixICCL::BoundsChecker<class MatrixICCL::ArrFormat<class MatrixICCL::StatExt<struct MatrixDSL::int_number<int,7>,struct MatrixDSL::int_number<int,7>>,class MatrixICCL::Rect<class MatrixICCL::StatExt<struct MatrixDSL::int_number<int,7>,struct MatrixDSL::int_number<int,7>>>,class MatrixICCL::Dyn2DCContainer<class MATRIX_ASSEMBLE_COMPONENTS<class MATRIX_DSL_ASSIGN_DEFAULTS<class MATRIX_DSL_PARSER<struct MatrixDSL::matrix<int,struct MatrixDSL::structure<struct MatrixDSL::rect<struct MatrixDSL::stat_val<struct MatrixDSL::int_number<int,7>>,struct MatrixDSL::stat_val<struct MatrixDSL::int_number<int,7>>,struct MatrixDSL::unspecified_DSL_feature>,struct MatrixDSL::dense<struct MatrixDSL::unspecified_DSL_feature>,struct Ma…

Generated from (A + B) * C

Page 21: Language and Ontology

Alternative

Page 22: Language and Ontology

Maintaining Abstractions

Source correlation

Ability to track source information through expansions

Helps programmers understand feedback in terms of original source

Page 23: Language and Ontology

Interacting Abstractions

Elaboration tracking

Keeps track of history of transformations on terms

Helps designers (and programmers) debug in the presence of complex interactions

Page 24: Language and Ontology

Requirement:Generalize Domain

Even common languages have lots of “little” languages in them

Macros are often limited to the expression and definition language(define (factorial (int n) : int) …)

Expansion uses a protocol to determine “latest version” of each language

Page 25: Language and Ontology

Requirement:Generalize Expansion

Macros are traditionally source-to-source; generalize by

giving control over expansion of sub-expressions

allowing intermediate stages to produce non-source output

enriching with attribute specifications (both threaded and unthreaded)

Page 26: Language and Ontology

RecapWhat we have described is a generalization

of macros to extend to full compilation: Macros Compilers

We provide both mechanism and policy:several incremental stagescommon framework, so designers can

combine these in a single specification

Page 27: Language and Ontology

Requirement:Modularize Languages

Languages are defined as “vocabularies”

These have abstract parent languagesDesigners can compose them to create

complete languages(analogous to “mixins” for classes)

This makes specifications much more coherent and reusable

Page 28: Language and Ontology

Languages as Layers

Base Language 1

Base Language 2

L1

L2L3

Base Language 1

L1

L3

Page 29: Language and Ontology

Summary

Experience shows our system ispractical and efficient

Key features:definition conveniences (…, hygiene)source correlationmacros-to-compilers continuumlanguage mixins

Page 30: Language and Ontology

Conclusion

We havemade a case for extensible languagesdescribed several “challenge”

features to demand of programming environments

mentioned how we implement these features