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

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, a la Abdali. The target code uses a control operator in direct style, a la Landin. In fact, the control operator used is almost Landin's J--hence our title. Our translation thus complements a continuation-passing translation a 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.

[1]  Corrado Böhm,et al.  Flow diagrams, turing machines and languages with only two formation rules , 1966, CACM.

[2]  William H. Burge,et al.  Recursive Programming Techniques , 1975 .

[3]  Richard M. Stallman Phantom Stacks: If You Look Too Hard, They Aren't There , 1980 .

[4]  Simon L. Peyton Jones,et al.  Imperative functional programming , 1993, POPL '93.

[5]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[6]  David Flanagan,et al.  The Ruby Programming Language , 2007 .

[7]  Olivier Danvy,et al.  A Rational Deconstruction of Landin's SECD Machine , 2003, IFL.

[8]  Florian Loitsch Scheme to JavaScript compilation , 2009 .

[9]  John McCarthy,et al.  Towards a Mathematical Science of Computation , 1962, IFIP Congress.

[10]  Martin Odersky,et al.  Tail call elimination on the Java Virtual Machine , 2001, Electron. Notes Theor. Comput. Sci..

[11]  Olivier Danvy,et al.  On the static and dynamic extents of delimited continuations , 2005, Sci. Comput. Program..

[12]  P. J. Landin,et al.  Correspondence between ALGOL 60 and Church's Lambda-notation , 1965, Commun. ACM.

[13]  Donald E. Knuth,et al.  Structured Programming with go to Statements , 1974, CSUR.

[14]  Jean-Yves Girard,et al.  Locus Solum: From the rules of logic to the logic of rules , 2001, Mathematical Structures in Computer Science.

[15]  Cicely M. Popplewell Information processing 1962 : proceedings of IFIP Congress 62 , 1963 .

[16]  Yasuhiko Minamide,et al.  Selective Tail Call Elimination , 2003, SAS.

[17]  John C. Reynolds,et al.  Definitional Interpreters Revisited , 1998, High. Order Symb. Comput..

[18]  Olivier Danvy,et al.  Partial Evaluation of Pattern Matching in Strings , 1989, Inf. Process. Lett..

[19]  Carl Hewitt,et al.  Behavioral semantics of nonrecursive control structures , 1974, Symposium on Programming.

[20]  Peter Lee,et al.  No assembly required: compiling standard ML to C , 1992, LOPL.

[21]  Alan Bundy,et al.  Constructing Induction Rules for Deductive Synthesis Proofs , 2006, CLASE.

[22]  Philip Wadler,et al.  The essence of functional programming (Invited talk) , 1997 .

[23]  Donald E. Knuth,et al.  Fast Pattern Matching in Strings , 1977, SIAM J. Comput..

[24]  Mitchell Wand,et al.  Trampolined style , 1999, ICFP '99.

[25]  C. Talcott The essence of rum: a theory of the intensional and extensional aspects of lisp-type computation (program transformation, closure, continuation structure, comparison-relation) , 1985 .

[26]  Robert Hieb,et al.  Engines From Continuations , 1989, Comput. Lang..

[27]  John McCarthy,et al.  Recursive functions of symbolic expressions and their computation by machine, Part I , 1960, Commun. ACM.

[28]  John McCarthy A Formal Description of a Subset of Algol , 1964 .

[29]  Melvin E. Conway,et al.  Design of a separable transition-diagram compiler , 1963, CACM.

[30]  Eugenio Moggi,et al.  Notions of Computation and Monads , 1991, Inf. Comput..

[31]  Jr. Guy L. Steele,et al.  Rabbit: A Compiler for Scheme , 1978 .

[32]  S. Kamal Abdali A Lambda-Calculus Model of Programming Languages - I. Simple Constructs , 1976, Comput. Lang..

[33]  Lockwood Morris The next 700 formal language descriptions , 1993, LISP Symb. Comput..

[34]  P. J. Landin,et al.  The next 700 programming languages , 1966, CACM.

[35]  Francis Lockwood Morris Correctness of translations of programming languages--an algebraic approach , 1972 .

[36]  Philip Wadler,et al.  The essence of functional programming , 1992, POPL '92.

[37]  Antoni W. Mazurkiewicz,et al.  Proving Algorithms by Tail Functions , 1971, Inf. Control..

[38]  Olivier Danvy,et al.  Sur un Exemple de Patrick Greussay , 2004 .

[39]  Drew McDermott,et al.  An efficient environment allocation scheme in an interpreter for a lexically-scoped LISP , 1980, LISP Conference.

[40]  Alan Bawden Reification without evaluation , 1988, LFP '88.

[41]  Nicolas Markey,et al.  On the Expressiveness and Complexity of ATL , 2007, FoSSaCS.

[42]  Paul Hudak,et al.  ORBIT: an optimizing compiler for scheme , 1986, SIGPLAN '86.

[43]  John C. Reynolds,et al.  Definitional Interpreters for Higher-Order Programming Languages , 1972, ACM '72.

[44]  Peter J. Landin Histories of Discoveries of Continuations: Belles-Lettres with Equivocal Tenses , 1997 .

[45]  S. Kamal Abdali A Lambda-Calculus Model of Programming Languages - II. Jumps and Procedures , 1976, Comput. Lang..

[46]  Hayo Thielecke,et al.  Comparing Control Constructs by Double-Barrelled CPS , 2002, High. Order Symb. Comput..

[47]  Michael J. Fischer,et al.  Lambda-calculus schemata , 1993, LISP Symb. Comput..

[48]  David S. Wise,et al.  Standard, Storeless Semantics for ALGOL-Style Block Structure and Call-by Name , 1986, Mathematical Foundations of Programming Semantics.

[49]  David Herman,et al.  Implementing Continuation Marks in Javascript , 2008 .