skip to main content
research-article

Contracts for domain-specific languages in Ruby

Published:14 October 2014Publication History
Skip Abstract Section

Abstract

This paper concerns object-oriented embedded DSLs, which are popular in the Ruby community but have received little attention in the research literature. Ruby DSLs implement language keywords as implicit method calls to self; language structure is enforced by adjusting which object is bound to self in different scopes. While Ruby DSLs are powerful and elegant, they suffer from a lack of specification. In this paper, we introduce contracts for Ruby DSLs, which allow us to attribute blame appropriately when there are inconsistencies between an implementation and client. We formalize Ruby DSL contract checking in DSL, a core calculus that uses premethods with instance evaluation to enforce contracts. We then describe RDL, an implementation of Ruby DSL contracts. Finally, we present two tools that automatically infer RDL contracts: TypeInfer infers simple, type-like contracts based on observed method calls, and DSLInfer infers DSL keyword scopes and nesting by generating and testing candidate DSL usages based on initial examples. The type contracts generated by TypeInfer work well enough, though they are limited in precision by the small number of tests, while DSLInfer finds almost all DSL structure. Our goal is to help users understand a DSL from example programs.

References

  1. An, J., Chaudhuri, A., Foster, J.S., Hicks, M.: Dynamic Inference of Static Types for Ruby. In: Principles of Programming Languages (POPL). pp. 459--472 (2011) Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Ancona, D., Ancona, M., Cuni, A., Matsakis, N.: RPython: a Step Towards Reconciling Dynamically and Statically Typed OO Languages. In: DLS 2007. pp. 53--64 (2007) Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Anderson, C., Giannini, P., Drossopoulou, S.: Towards Type Inference for JavaScript. In: European Conference on Object-Oriented Programming. LNCS, vol. 3586, pp. 428--452 (2005) Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Austin, T.H., Disney, T., Flanagan, C.: Virtual values for language extension. In: Object-Oriented Programming, Systems, Languages, and Applications. pp. 921--938 (2011) Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. Aycock, J.: {Aggressive Type Inference}. In: International Python Conference (2000)Google ScholarGoogle Scholar
  6. Bentley, J.: Programming pearls: little languages. Communications of the ACM 29(8), 711--721 (Aug 1986) Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Bhargava, A.: contracts.ruby (2012), https://github.com/egonSchiele/contracts.rubyGoogle ScholarGoogle Scholar
  8. Claessen, K., Ljunglof, P.: Typed logical variables in Haskell. In: Proceedings of the 2000 Haskell Workshop (2000)Google ScholarGoogle Scholar
  9. Clinger, W., Rees, J.: Macros that work. In: Symposium on Principles of Programming Languages. pp. 155--162 (1991) Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. van Deursen, A., Klint, P., Visser, J.: Domain-specific languages: An annotated bibliography. SIGPLAN Not. 35(6), 26--36 (Jun 2000) Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in Scheme. LISP and Symbolic Computation 5(4), 295--326 (1993) Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Elliott, C.: Programming graphics processors functionally. In: Proceedings of the 2004 Haskell Workshop (2004), http://conal.net/papers/Vertigo/ Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Felleisen, M., Friedman, D.P.: Control operators, the SECD-machine, and the ε-calculus. In: Formal Description of Programming Concepts III. pp. 193--217 (1986)Google ScholarGoogle Scholar
  14. Findler, R.B., Blume, M.: Contracts as pairs of projections. In: International Conference on Functional and Logic Programming. pp. 226--241 (2006) Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: International Conference on Functional Programming. pp. 48--59 (Oct 2002) Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Flatt, M.: Composable and Compilable Macros: You Want it When? In: International Conference on Functional Programming. pp. 72--83 (2002) Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Flatt, M., Culpepper, R., Darais, D., Findler, R.B.: {Macros that Work Together. Journal of Functional Programming 22, 181--216 (2012) Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Flatt, M., PLT: Reference: Racket. Tech. Rep. PLT-TR-2010--1, PLT Inc. (2010), http://racket-lang.org/tr1/Google ScholarGoogle Scholar
  19. Furr, M., An, J., Foster, J.S., Hicks, M.: The Ruby Intermediate Langauge. In: Dynamic Languages Symposium (DLS). pp. 89--98. Orlando, Florida (October 2009) Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Guy L. Steele, Jr.: Common LISP: the Language, 2nd Edition. Digital Press, Newton, MA, USA (1990) Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Hudak, P.: Building domain-specific embedded languages. ACM Computing Surveys 28 (1996) Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Hudak, P.: Modular domain specific languages and tools. In: in Proceedings of Fifth International Conference on Software Reuse. pp. 134--142. IEEE Computer Society Press (1998) Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Leijen, D., Meijer, E.: Domain specific embedded compilers. In: Conference on Domain-specific Languages. pp. 109--122 (1999) Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Ousterhout, J.K., Jones, K.: Tcl and the Tk Toolkit, 2nd Edition. Addison-Wesley Professional, Boston, MA, USA (2009) Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Perrotta, P.: Metaprogramming Ruby. Pragmatic Bookshelf (2010) Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Reid, A., Peterson, J., Hager, G., Hudak, P.: Prototyping real-time vision systems: an experiment in dsl design. In: International Conference on Software engineering. pp. 484--493 (1999) Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Ren, B.M., Toman, J., Strickland, T.S., Foster, J.S.: {The {R}uby Type Checker}. In: Symposium on Applied Computing. pp. 1565--1572 (2013) Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Riehl, J.: Language embedding and optimization in Mython. In: Symposium on Dynamic Languages. pp. 39--48. DLS '09 (2009) Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Sperber, M., Dybvig, R.K., Flatt, M., Van Straaten, A., Findler, R., Matthews, J.: Revised6 Report on the Algorithmic Language Scheme. Journal of Functional Programming 19, 1--301 (2009) Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Strickland, T.S., Felleisen, M.: Contracts for first-class classes. In: Symposium on Dynamic Languages. pp. 97--111 (Oct 2010) Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. Strickland, T.S., Tobin-Hochstadt, S., Findler, R.B., Flatt, M.: Chaperones and Impersonators: Run-time Support for Reasonable Interposition. In: Object-Oriented Programming, Systems, Languages, and Applications. pp. 943--962 (2012) Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Team, R.C.: R Language Definition. http://cran.r-project.org/doc/manuals/r-release/R-lang.htmlGoogle ScholarGoogle Scholar
  33. Thiemann, P.: Modeling HTML in Haskell. In: International Workshop on Practical Aspects of Declarative Languages. pp. 263--277 (2000) Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Thiemann, P.: Towards a Type System for Analyzing JavaScript. In: European Symposium on Programming. LNCS, vol. 3444, pp. 408--422 (2005) Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Wickham, H.: Advanced R programming (Nov 2013), http://adv-r.had.co.nz/dsl.htmlGoogle ScholarGoogle Scholar

Index Terms

  1. Contracts for domain-specific languages in Ruby

        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 50, Issue 2
          DLS '14
          February 2015
          146 pages
          ISSN:0362-1340
          EISSN:1558-1160
          DOI:10.1145/2775052
          • Editor:
          • Andy Gill
          Issue’s Table of Contents
          • cover image ACM Conferences
            DLS '14: Proceedings of the 10th ACM Symposium on Dynamic languages
            October 2014
            160 pages
            ISBN:9781450332118
            DOI:10.1145/2661088

          Copyright © 2014 ACM

          Publisher

          Association for Computing Machinery

          New York, NY, United States

          Publication History

          • Published: 14 October 2014

          Check for updates

          Qualifiers

          • research-article

        PDF Format

        View or Download as a PDF file.

        PDF

        eReader

        View online with eReader.

        eReader
        About Cookies On This Site

        We use cookies to ensure that we give you the best experience on our website.

        Learn more

        Got it!