Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article

Contracts for domain-specific languages in Ruby

Published: 14 October 2014 Publication History

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)
[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)
[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)
[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)
[5]
Aycock, J.: {Aggressive Type Inference}. In: International Python Conference (2000)
[6]
Bentley, J.: Programming pearls: little languages. Communications of the ACM 29(8), 711--721 (Aug 1986)
[7]
Bhargava, A.: contracts.ruby (2012), https://github.com/egonSchiele/contracts.ruby
[8]
Claessen, K., Ljunglof, P.: Typed logical variables in Haskell. In: Proceedings of the 2000 Haskell Workshop (2000)
[9]
Clinger, W., Rees, J.: Macros that work. In: Symposium on Principles of Programming Languages. pp. 155--162 (1991)
[10]
van Deursen, A., Klint, P., Visser, J.: Domain-specific languages: An annotated bibliography. SIGPLAN Not. 35(6), 26--36 (Jun 2000)
[11]
Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in Scheme. LISP and Symbolic Computation 5(4), 295--326 (1993)
[12]
Elliott, C.: Programming graphics processors functionally. In: Proceedings of the 2004 Haskell Workshop (2004), http://conal.net/papers/Vertigo/
[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)
[14]
Findler, R.B., Blume, M.: Contracts as pairs of projections. In: International Conference on Functional and Logic Programming. pp. 226--241 (2006)
[15]
Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: International Conference on Functional Programming. pp. 48--59 (Oct 2002)
[16]
Flatt, M.: Composable and Compilable Macros: You Want it When? In: International Conference on Functional Programming. pp. 72--83 (2002)
[17]
Flatt, M., Culpepper, R., Darais, D., Findler, R.B.: {Macros that Work Together. Journal of Functional Programming 22, 181--216 (2012)
[18]
Flatt, M., PLT: Reference: Racket. Tech. Rep. PLT-TR-2010--1, PLT Inc. (2010), http://racket-lang.org/tr1/
[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)
[20]
Guy L. Steele, Jr.: Common LISP: the Language, 2nd Edition. Digital Press, Newton, MA, USA (1990)
[21]
Hudak, P.: Building domain-specific embedded languages. ACM Computing Surveys 28 (1996)
[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)
[23]
Leijen, D., Meijer, E.: Domain specific embedded compilers. In: Conference on Domain-specific Languages. pp. 109--122 (1999)
[24]
Ousterhout, J.K., Jones, K.: Tcl and the Tk Toolkit, 2nd Edition. Addison-Wesley Professional, Boston, MA, USA (2009)
[25]
Perrotta, P.: Metaprogramming Ruby. Pragmatic Bookshelf (2010)
[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)
[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)
[28]
Riehl, J.: Language embedding and optimization in Mython. In: Symposium on Dynamic Languages. pp. 39--48. DLS '09 (2009)
[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)
[30]
Strickland, T.S., Felleisen, M.: Contracts for first-class classes. In: Symposium on Dynamic Languages. pp. 97--111 (Oct 2010)
[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)
[32]
Team, R.C.: R Language Definition. http://cran.r-project.org/doc/manuals/r-release/R-lang.html
[33]
Thiemann, P.: Modeling HTML in Haskell. In: International Workshop on Practical Aspects of Declarative Languages. pp. 263--277 (2000)
[34]
Thiemann, P.: Towards a Type System for Analyzing JavaScript. In: European Symposium on Programming. LNCS, vol. 3444, pp. 408--422 (2005)
[35]
Wickham, H.: Advanced R programming (Nov 2013), http://adv-r.had.co.nz/dsl.html

Cited By

View all
  • (2021)SimTyper: sound type inference for Ruby using type equality predictionProceedings of the ACM on Programming Languages10.1145/34854835:OOPSLA(1-27)Online publication date: 15-Oct-2021
  • (2019)Type-level computations for Ruby librariesProceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation10.1145/3314221.3314630(966-979)Online publication date: 8-Jun-2019
  • (2017)Type systems as macrosACM SIGPLAN Notices10.1145/3093333.300988652:1(694-705)Online publication date: 1-Jan-2017
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

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
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 the author(s) 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: 14 October 2014
Published in SIGPLAN Volume 50, Issue 2

Check for updates

Author Tags

  1. domain-specific languages
  2. software contracts

Qualifiers

  • Research-article

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)3
  • Downloads (Last 6 weeks)0
Reflects downloads up to 12 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2021)SimTyper: sound type inference for Ruby using type equality predictionProceedings of the ACM on Programming Languages10.1145/34854835:OOPSLA(1-27)Online publication date: 15-Oct-2021
  • (2019)Type-level computations for Ruby librariesProceedings of the 40th ACM SIGPLAN Conference on Programming Language Design and Implementation10.1145/3314221.3314630(966-979)Online publication date: 8-Jun-2019
  • (2017)Type systems as macrosACM SIGPLAN Notices10.1145/3093333.300988652:1(694-705)Online publication date: 1-Jan-2017
  • (2017)Type systems as macrosProceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages10.1145/3009837.3009886(694-705)Online publication date: 1-Jan-2017
  • (2016)Just-in-time static type checking for dynamic languagesACM SIGPLAN Notices10.1145/2980983.290812751:6(462-476)Online publication date: 2-Jun-2016
  • (2016)Just-in-time static type checking for dynamic languagesProceedings of the 37th ACM SIGPLAN Conference on Programming Language Design and Implementation10.1145/2908080.2908127(462-476)Online publication date: 2-Jun-2016

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media