J Is for JavaScript: A Direct-Style Correspondence between Algol-Like Languages and JavaScript Using First-Class Continuations

  • Olivier Danvy
  • Chung-chieh Shan
  • Ian Zerny
Conference paper

DOI: 10.1007/978-3-642-03034-5_1

Volume 5658 of the book series Lecture Notes in Computer Science (LNCS)
Cite this paper as:
Danvy O., Shan C., Zerny I. (2009) J Is for JavaScript: A Direct-Style Correspondence between Algol-Like Languages and JavaScript Using First-Class Continuations. In: Taha W.M. (eds) Domain-Specific Languages. Lecture Notes in Computer Science, vol 5658. Springer, Berlin, Heidelberg

Abstract

It is a time-honored fashion to implement a domain-specific language (DSL) by translation to a general-purpose language. Such an implementation is more portable, but an unidiomatic translation jeopardizes performance because, in practice, language implementations favor the common cases. This tension arises especially when the domain calls for complex control structures. We illustrate this tension by revisiting Landin’s original correspondence between Algol and Church’s lambda-notation.

We translate domain-specific programs with lexically scoped jumps to JavaScript. Our translation produces the same block structure and binding structure as in the source program, à la Abdali. The target code uses a control operator in direct style, à la Landin. In fact, the control operator used is almost Landin’s J—hence our title. Our translation thus complements a continuation-passing translation à la Steele. These two extreme translations require JavaScript implementations to cater either for first-class continuations, as Rhino does, or for proper tail recursion. Less extreme translations should emit more idiomatic control-flow instructions such as for, break, and throw.

The present experiment leads us to conclude that translations should preserve not just the data structures and the block structure of a source program, but also its control structure. We thus identify a new class of use cases for control structures in JavaScript, namely the idiomatic translation of control structures from DSLs.

Download to read the full conference paper text

Copyright information

© IFIP International Federation for Information Processing 2009

Authors and Affiliations

  • Olivier Danvy
    • 1
  • Chung-chieh Shan
    • 2
  • Ian Zerny
    • 1
  1. 1.Department of Computer ScienceAarhus UniversityAarhus NDenmark
  2. 2.Department of Computer ScienceRutgers UniversityPiscatawayUSA