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

Research output: Contribution to journal/Conference contribution in journal/Contribution to newspaperConference articleResearchpeer-review

  • Olivier Danvy
  • Chung-chieh Shan, Rutgers University, United States
  • Ian Steven Zerny, Denmark
  • Department of Computer Science
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.
Original languageEnglish
Book seriesLecture Notes in Computer Science
Pages (from-to)1-19
Number of pages19
Publication statusPublished - 2009
EventIFIP TC 2 Working Conference, DSL 2009 - Oxford, United Kingdom
Duration: 15 Jul 200917 Jul 2009
Conference number: 1


ConferenceIFIP TC 2 Working Conference, DSL 2009
CountryUnited Kingdom

    Research areas

  • language embedding, proper tail recursion, first-class continuations, JavaScript, Landin

See relations at Aarhus University Citationformats

ID: 18797474