skip to main content
research-article

Languages as libraries

Published:04 June 2011Publication History
Skip Abstract Section

Abstract

Programming language design benefits from constructs for extending the syntax and semantics of a host language. While C's string-based macros empower programmers to introduce notational shorthands, the parser-level macros of Lisp encourage experimentation with domain-specific languages. The Scheme programming language improves on Lisp with macros that respect lexical scope.

The design of Racket---a descendant of Scheme---goes even further with the introduction of a full-fledged interface to the static semantics of the language. A Racket extension programmer can thus add constructs that are indistinguishable from "native" notation, large and complex embedded domain-specific languages, and even optimizing transformations for the compiler backend. This power to experiment with language design has been used to create a series of sub-languages for programming with first-class classes and modules, numerous languages for implementing the Racket system, and the creation of a complete and fully integrated typed sister language to Racket's untyped base language.

This paper explains Racket's language extension API via an implementation of a small typed sister language. The new language provides a rich type system that accommodates the idioms of untyped Racket. Furthermore, modules in this typed language can safely exchange values with untyped modules. Last but not least, the implementation includes a type-based optimizer that achieves promising speedups. Although these extensions are complex, their Racket implementation is just a library, like any other library, requiring no changes to the Racket implementation.

References

  1. Jonathan Bachrach and Keith Playford. The Java syntactic extender. In Proc. Conf. Object-Oriented Programming Systems, Languages, and Applications, pp. 31--42, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Eli Barzilay and John Clements. Laziness Without All the Hard Work. In Proc. Works. Functional and Declarative Programming in Education, pp. 9--13, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Martin Bravenboer and Eelco Visser. Concrete syntax for objects: domainspecific language embedding and assimilation without restrictions. In Proc. Conf. Object-Oriented Programming Systems, Languages, and Applications, pp. 365--383, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. John Clements, Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram Krishnamurthi. Fostering Little Languages. Dr. Dobb's Journal, pp. 16--24, 2004.Google ScholarGoogle Scholar
  5. William D. Clinger and Lars Thomas Hansen. Lambda, the ultimate label or a simple optimizing compiler for Scheme. In Proc. Conf. on LISP and functional programming, pp. 128--139, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Russ Cox, Tom Bergan, Austin T. Clements, Frans Kaashoek, and Eddie Kohler. Xoc, an extension-oriented compiler for systems programming. In Proc. Conf. Architectural Support for Programming Languages and Operating Systems, pp. 244--254, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Ryan Culpepper and Matthias Felleisen. Debugging hygienic macros. Science of Computer Programming 75(7), pp. 496--15, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Ryan Culpepper and Matthias Felleisen. Fortifying macros. In Proc. International Conf. on Functional Programming, pp. 235--246, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Ryan Culpepper, Scott Owens, and Matthew Flatt. Syntactic abstraction in component interfaces. In Proc. Conf. Generative Programming and Component Engineering, pp. 373--388, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Ryan Culpepper, Sam Tobin-Hochstadt, and Matthias Felleisen. Advanced Macrology and the Implementation of Typed Scheme. In Proc. Scheme and Functional Programming, 2007.Google ScholarGoogle Scholar
  11. R. Kent Dybvig. Chez Scheme Version 8 User's Guide. Cadence Research Systems, 2009.Google ScholarGoogle Scholar
  12. R. Kent Dybvig, Robert Hieb, and Carl Bruggeman. Syntactic abstraction in Scheme. Lisp and Symbolic Computation 5(4), pp. 295--326, 1992. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Marc Feeley and James S. Miller. A parallel virtual machine for efficient Scheme compilation. In Proc. Conf. on LISP and Functional Programming, pp. 119--130, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram Krishnamurthi. Building Little Languages With Macros. Dr. Dobb's Journal, pp. 45--49, 2004.Google ScholarGoogle Scholar
  15. David Fisher and Olin Shivers. Static semantics for syntax objects. In Proc. International Conf. on Functional Programming, pp. 111--121, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. David Fisher and Olin Shivers. Building language towers with Ziggurat. J. of Functional Programming 18(5-6), pp. 707--780, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Matthew Flatt. Composable and compilable macros: you want it when? In Proc. International Conf. on Functional Programming, pp. 72--83, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Matthew Flatt, Eli Barzilay, and Robert Bruce Findler. Scribble: closing the book on ad-hoc documentation tools. In Proc. International Conf. on Functional Programming, pp. 109--120, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Matthew Flatt and Matthias Felleisen. Units: Cool modules for HOT languages. In Proc. Conf. on Programming Language Design and Implementation, pp. 236--248, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Matthew Flatt, Robert Bruce Findler, and Matthias Felleisen. Scheme with classes, mixins, and traits. In Proc. Asian Symp. on Programming Languages and Systems, pp. 270--289, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Matthew Flatt and PLT. Reference: Racket. PLT Inc., PLT-TR-2010-1, 2010. http://racket-lang.org/tr1/.Google ScholarGoogle Scholar
  22. Richard P. Gabriel. Performance and Evaluation of LISP Systems. MIT Press, 1985. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Anwar Ghuloum, Amanda Sharp, Noah Clemons, Stefanus Du Toit, Rama Malladi, Mukesh Gangadhar, Michael McCool, and Hans Pabst. Array Building Blocks: A Flexible Parallel Programming Model for Multicore and Many-Core Architectures. Dr. Dobb's Journal, 2010.Google ScholarGoogle Scholar
  24. Pieter H. Hartel, Marc Feeley, Martin Alt, Lennart Augustsson, Peter Baumann, Marcel Beemster, Emmanuel Chailloux, Christine H. Flood, Wolfgang Grieskamp, John H. G. van Groningen, Kevin Hammond, BogumiB Hausman, Melody Y. Ivory, Richard E. Jones, Jasper Kamperman, Peter Lee, Xavier Leroy, Rafael D. Lins, Sandra Loosemore, Niklas Röjemo, Manuel Serrano, Jean-Pierre Talpin, Jon Thackray, Stephen Thomas, Pum Walters, Pierre Weis, and E.P. Wentworth. Benchmarking implementations of functional languages with 'pseudoknot' a float-intensive benchmark. J. of Functional Programming 6(4), pp. 621--655, 1996.Google ScholarGoogle ScholarCross RefCross Ref
  25. Manuel V. Hermenegildo, Francisco Bueno, Manuel Carro, Pedro Lopez, José F. Morales, and German Puebla. An overview of the Ciao multiparadigm language and program development environment and its design philosophy. In Concurrency, Graphs and Models. Springer-Verlag, pp. 209--237, 2008. Google ScholarGoogle Scholar
  26. Richard Andrew Kelsey. Compilation by Program Transformation. PhD dissertation, Yale University, 1989.Google ScholarGoogle Scholar
  27. Shriram Krishnamurthi. Linguistic Reuse. PhD dissertation, Rice University, 2001. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Shriram Krishnamurthi, Peter Walton Hopkins, Jay McCarthy, Paul T. Graunke, Greg Pettyjohn, and Matthias Felleisen. Implementation and use of the PLT Scheme web server. Higher-Order and Symbolic Computing 20(4), pp. 431--460, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Simon Marlow. Haskell 2010 Language Report. 2010.Google ScholarGoogle Scholar
  30. Robin Milner, Mads Tofte, Robert Harper, and David MacQueen. The Definition of Standard ML, Revised Edition. MIT Press, 1997. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Nathaniel Nystrom, Michael Clarkson, and Andrew Myers. Polyglot: an extensible compiler framework for Java. In Proc. International Conf. on Compiler Construction, pp. 138--152, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Simon L Peyton Jones. Compiling Haskell by program transformation a report from the trenches. In Proc. European Symp. on Programming, pp. 18--44, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Hari Prashanth K R and Sam Tobin-Hochstadt. Functional data structures for Typed Racket. In Proc. Works. Scheme and Functional Programming, pp. 1--7, 2010.Google ScholarGoogle Scholar
  34. Manuel Serrano and Pierre Weis. Bigloo: a portable and optimizing compiler for strict functional languages. In Proc. Static Analysis Symp., pp. 366--381, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Michael Sperber, Matthew Flatt, Anton Van Straaten, R. Kent Dybvig, Robert Bruce Findler, and Jacob Matthews. Revised6 report on the algorithmic language Scheme. J. of Functional Programming 19(S1), pp. 1--301, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Guy L. Steele Jr. Common Lisp: The Language. Second edition. Digital Press, 1994. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Guy L. Steele Jr. Growing a language, Keynote at OOPSLA 1998. Higher-Order and Symbolic Computation 12(3), pp. 221--236, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Guy L. Steele Jr. and Richard P. Gabriel. The evolution of Lisp. In Proc. Conf. on History of Programming Languages, pp. 231--270, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. T. Stephen Strickland, Sam Tobin-Hochstadt, and Matthias Felleisen. Practical Variable-Arity Polymorphism. In Proc. European Symp. on Programming, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Sam Tobin-Hochstadt and Matthias Felleisen. Interlanguage refactoring: from scripts to programs. In Proc. Dynamic Languages Symp., pp. 964--974, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Sam Tobin-Hochstadt and Matthias Felleisen. The design and implementation of Typed Scheme. In Proc. Symp. on Principles of Programming Languages, pp. 395--406, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Sam Tobin-Hochstadt and Matthias Felleisen. Logical types for untyped languages. In Proc. International Conf. on Functional Programming, pp. 117--128, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Eugene Kohlbecker. Syntactic Extensions in the Programming Language Lisp. PhD dissertation, Indiana University, 1986. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Languages as libraries

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 46, Issue 6
        PLDI '11
        June 2011
        652 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1993316
        Issue’s Table of Contents
        • cover image ACM Conferences
          PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation
          June 2011
          668 pages
          ISBN:9781450306638
          DOI:10.1145/1993498
          • General Chair:
          • Mary Hall,
          • Program Chair:
          • David Padua

        Copyright © 2011 ACM

        Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 4 June 2011

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader