In some domains of programming it’s common to want to write a data structure or algorithm that can work with elements of many different types, such as a generic list or a sorting algorithm that only needs a comparison function.
Staapl is a collection of abstractions for metaprogramming microcontrollers from within PLT Scheme. The core of the system is a programmable code generator structured around a functional concatenative macro language adapted to a 2-stack machine model. On top of this it includes a syntax frontend for creating Forth style languages, a backend code generator for the Microchip PIC18 microcontroller architecture, and interaction tools for shortening the edit-compile-run cycle. It is structured as a code library to facilitate integration into larger systems employing a model-based design approach. The primary, practical goal is to provide a tool chain for programming low-end (8-bit) microcontrollers in a Forth-style language extended with powerful metaprogramming facilities. The secondary goal is to generalize and modularize this approach and extend it in two directions: to provide a standard machine model as an abstraction point for a large class of small embedded processo
"Generalized Algebraic Data Structures" have become a a hot new topic. They have recently been added to the GHC compiler. They support the construction, maintenance, and propagation of semantic properties of programs using powerful old ideas about types (the Curry-Howard Isomorphism) in surprisingly easy to understand new ways. The language Omega was designed and implemented to demonstrate their utility. Here a a few talks I gave that explains how they work. Also class lectures
for 6.10 We show how to build a quasiquoter for a simple mathematical expression language. Although the example is small, it demonstrates all aspects of building a quasiquoter. We do not mean to suggest that one gains much from a quasiquoter for such a small language relative to using abstract syntax directly except from a pedagogical point of view---this is just a tutorial!
An ingenious set of combinators for expressing pattern matching in a type-safe way. No ADTs required. Opens up the possibility of programming languages where we can declare new binding forms just as we declare new functions. abstract: Macros still have not made their way into typed higher-order programming languages such as Haskell and Standard ML. Therefore, to extend the expressiveness of Haskell or Standard ML gradually, one must express new linguistic features in terms of functions that fit within the static type systems of these languages. This is particularly challenging when introducing features that span across multiple types and that bind variables. We address this challenge by developing, in a step-by-step manner, mechanisms for encoding patterns and pattern matching in Haskell in a type-safe way.
c2005 Most new ideas in software developments are really new variations on old ideas. This article describes one of these, the growing idea of a class of tools that I call Language Workbenches - examples of which include Intentional Software, JetBrains's Meta Programming System, and Microsoft's Software Factories. These tools take an old style of development - which I call language oriented programming and use IDE tooling in a bid to make language oriented programming a viable approach. Although I'm not enough of a prognosticator to say whether they will succeed in their ambition, I do think that these tools are some of the most interesting things on the horizon of software development. Interesting enough to write this essay to try to explain, at least in outline, how they work and the main issues around their future usefulness.
In our professional software development, we have focused on finding ways to help developers work more effectively. Despite the range of programming languages available today, we are still limited by them. It makes sense to extend the existing languages to create more domain-oriented ones, which allow writing programs on a higher level and in a manner that is more natural to each domain. With an instrument that allows creating language constructs as simple as creating classes or methods is in a conventional language, you can significantly change the way you develop software. This new style of programming, when you create specialized languages, use them to develop software, and extend them when and how required, is called Language Oriented Programming (LOP). MPS Story Meta Programming System started in 2003 as a research project. In 2004, its underlying concepts were described in the Language Oriented Programming article.
Standard ML is often used to implement another language L, for example, the syntax of the HOL logic in hol90 or the syntax of CCS for the Concurrency Workbench. Typically, one defines the abstract syntax of L by a datatype declaration. Then useful functions over the datatype can be defined (such as finding the free variables of a formula when L is a logic). Soon afterwards, one concludes that concrete syntax is easier for humans to read than abstract syntax, and so writes a parser and prettyprinter for L. In the situation just outlined, ML is called the metalanguage, and L is called the object language, or OL. (Edinburgh/INRIA/Cambridge ML, the precursor to Standard ML, was originally a programming metalanguage for a particular object language, the LCF logic.) The purpose of a quotation/antiquotation mechanism is to allow one to embed expressions in the object language's concrete syntax inside of ML programs, and to mix the object language expressions with ML expressions.
Grammar Based Definition Of Metaprogramming Systems Program-Transformation.Org: The Program Transformation Wiki Robert Cameron? and Robert Ito?. Grammar-Based Definition of Metaprogramming Systems. ACM Transactions on Programming Languages and Systems Vol. 6, No. 1, January 1984, Pages 20-54. (ACM Digital Library) Summary This paper describes the GRAMPS method for meta-programming. GRAMPS stands for GRAmmar-based MetaProgramming Scheme. The method basically describes how abstract syntax tree? manipulation can be done in a general-purpose programming language. Given an API for analyzing and constructing syntax trees, transformations can be expressed.
E. Visser. Meta-programming with concrete object syntax. In D. Batory, C. Consel, and W. Taha, editors, Generative Programming and Component Engineering (GPCE'02), volume 2487 of Lecture Notes in Computer Science, pages 299-315, Pittsburgh, PA, USA, October 2002. Springer-Verlag. Meta programs manipulate structured representations (abstract syntax) of programs. The distance between the concrete syntax meta-programmers use to reason about programs and the notation for abstract syntax manipulation provided by general purpose (meta-) programming languages is too great for many applications. In this paper it is shown how the syntax definition formalism SDF can be employed to fit a meta-programming language with concrete syntax notation for composing and analyzing object programs. As a case study, the addition of concrete syntax to the program transformation language Stratego is presented. The approach is then generalized to arbitrary meta-languages.
Staged Meta Programming * MetaML does not restrict the stages to only run or compile Template Meta Programming * Template Haskell * C++ Templates Macro Systems Lexical macro systems are often independent of specific PL. Macro system that operate on a structured representations of source code are called syntax macros. Some macro systems allow the definition of a context-free syntax for the arguments of the macro. Hygience macro systems avoid unintended capturing of identifiers that are used in the context or in the macro definition. * Lisp Macros * Scheme R5RS Macros * Syntax macros in Bigwig * Maya Aspect-Oriented Programming * AspectJ * AspectL Quotation and Antiquotation * Camlp4 * SML/NJ Object Language Embedding with Quote/Antiquote * Isabelle's Logics * Programmable Syntax Macros * Meta Programming with Concrete Object Syntax Systems * GRAMPS
A Taxonomy of meta-programming systems. In a meta-programming system meta-programs manipulate object-programs. Meta-programs may construct object-programs, combine object-program fragments into larger object-programs, observe the structure and other properties of object-programs, and execute object-programs to obtain their values. There are two important kind of meta-programming scenarios: program generators, and program analyses. Each has a number of distinguishing characteristics 1. Generator 1. Representation: Strings vs. Algebraic datatype vs. Quasi-quote 2. Automatic vs. Manual annotation 3. Static vs. Runtime Generator 4. Homo vs. Heterogeneous 5. Typed vs. un-Typed 1. Statically vs. Dynamically Typed 6. 2-stage vs. N-stage 2. Analysis 1. Homo vs. Heterogeneous 2. HOAS vs. First Order Syntax 3. Typed vs. un-Typed
A compiled, type-safe, multi-stage programming language. MetaOCaml is a multi-stage extension of the OCaml programming language, and provides three basic constructs called Brackets, Escape, and Run for building, combining, and executing future-stage computations, respectively. (Please read README-META file in distribution for MetaOCaml's syntax for these constructs). MetaOCaml is a compiled dialect of MetaML. Download current (February 3nd, 2006) (or archived distributions) and follow instructions in INSTALL-META. For Windows, you'll need Cygwin Hot from the Press!: Science of Computer Programming special issue on MetaOCaml Learn more about multi-stage programming.
Most applications consist of a big number of model- or so called domain-objects. Building different views, editors, and reports; querying, validating and storing those objects is very repetitive and error-prone, if an object changes its shape frequently. Magritte is a fully dynamic meta-description framework that helps to solve those problems, while keeping the full power to the programmer in all aspects. Moreover since Magritte is described in itself, you can let your users modify the meta-world and add their own fields and forms without writing a single line of code.
au:chlipala Ur introduces richer type system features into FP. Ur is functional, pure, statically-typed, and strict. Ur supports metaprogramming based on row types. Ur/Web is standard library and associated rules for parsing and optimization. Ur/Web supports construction of dynamic web applications backed by SQL databases. The signature of the standard library is such that well-typed Ur/Web programs "don't go wrong" in a very broad sense. They also may not: * Suffer from any kinds of code-injection attacks * Return invalid HTML * Contain dead intra-application links * Have mismatches between HTML forms and the fields expected by their handlers It is also possible to use metaprogramming to build significant application pieces by analysis of type structure - demo includes an ML-style functor for building an admin interface for an arbitrary SQL table. The Ur/Web compiler also produces very efficient object code that does not use gc
Stratego/XT is a language and toolset for constructing stand-alone program transformation systems. It combines the Stratego transformation language with the XT toolset of transformation components, providing a framework for constructing stand-alone program transformation systems. The Stratego language is based around a programming paradigm called strategic term rewriting. It provides rewrite rules for expressing basic transformation steps. The application of these rules can be controlled using strategies, a form of subroutines. The XT toolset provides reusable transformation components and declarative languages for deriving new components. Program transformations often operate by modifying the (AST). In Stratego it is also possible to specify transformations using concrete syntax. This allows programmers to express a transformation using the familiar (and often more concise) syntax of the object programming language, while it internally still operates on the AST.
As you probably can tell Maude sets out to solve a different set of problems than ordinary imperative languages. It is a formal reasoning tool, which can help us verify that things are "as they should", and show us why they are not if this is the case. Maude lets us define formally what we mean by some concept in a very abstract manner, but we can describe what is thought to be the equal concerning our theory (equations) and what state changes it can go through (rewrite rules). This is useful to validate security protocols and critical code. The Maude system has proved flaws in cryptography protocols by just specifying what the system can do , and by looking for unwanted situations the protocol can be showed to contain bugs, not programming bugs but situations happen that are hard to predict just by walking down the "happy path" as most developers do. We can use Maude's built-in search to look for unwanted states, or it can be used to show that no such states can be reached.
One of the key goals of rewriting logic from its beginning has been to provide a semantic and logical framework in which many models of computation and languages can be naturally represented. There is by now very extensive evidence supporting the claim that rewriting logic is indeed a very flexible and simple logical and semantic framework. From a language design point of view the obvious question to ask is: how can a rewriting logic language best support logical and semantic framework applications, so that it becomes a metalanguage in which a very wide variety of logics and languages can be both semantically defined, and implemented? Our answer is: by being reflective. This paper discusses our latest language design and implementation work on Maude as a reflective metalanguage in which entire environments---including syntax definition, parsing, pretty printing, execution, and input/output---can be defined for a language or logic L of choice.
In most other programming languages, new abstractions are built by writing code on /top/ of existing abstractions. But in lisp, its possible to build new abstractions by writing code *beneath* existing code. Abstract: A partial evaluator automatically specializes a program with respect to some of its input. This article shows how the idea comes up naturally when you write program generators by hand, then builds a basic online partial evaluation library and puts it to work transforming an interpreter into a compiler. 0. Introduction Mainstream programmers think of writing an interpreter or a compiler as a major job, worth doing only for a major problem. They know this because the languages they use every day have big, serious implementations, and the compiler class they took in school had them write just one big, semi-serious compiler. Lispers know better: all the textbooks show how to write a Lisp interpreter in about a page of code.
Treetop is a language for describing languages. Combining the elegance of Ruby with cutting-edge parsing expression grammars, it helps you analyze syntax with revolutionarily ease.
Reflection is a programming language technique that achieves dynamic adaptability. It can be used to reach aspect –or any kind of application– adaptation at runtime. Most runtime reflective systems are based on the ability to modify the programming la
I have been thinking much about Metaprogramming lately. I have come to the conclusion that I would like to see more examples and explanations of these techniques. For good or bad, metaprogramming has entered the Ruby community as the standard way of accom
JavaScript, even more so than VB, has to be the Rodney Dangerfield of programming languages. I'm going to blow whatever credibility I might have by saying "I actually like programming in JavaScript." I'm actually building a lot of the screens in StoryTeller with JavaScript running in a WebBrowser control because I think I can do dynamic layout much faster with JavaScript than a WinForms screen. Besides, the point of a "side" project is to do stuff you don't get to do at your day job.