Language interoperability and logic programming languages

We discuss P#, our implementation of a tool which allows interoperation between a concurrent superset of the Prolog programming language and C#. This enables Prolog to be used as a native implementation language for Microsoft’s .NET platform. P# compiles a linear logic extension of Prolog to C# source code. We can thus create C# objects from Prolog and use C#’s graphical, networking and other libraries. P# was developed from a modified port of the Prolog to Java translator, Prolog Cafe. We add language constructs on the Prolog side which allow concurrent Prolog code to be written. We add a primitive predicate which evaluates a Prolog structure on a newly forked thread. Communication between threads is based on the unification of variables contained in such a structure. It is also possible for threads to communicate through a globally accessible table. All of the new features are available to the programmer through new built-in Prolog predicates. We present three case studies. The first is an application which allows several users to modify a database. The users are able to disconnect from the database and to modify their own copies of the data before reconnecting. On reconnecting, conflicts must be resolved. The second is an object-oriented assistant, which allows the user to query the contents of a C# namespace or Java package. The third is a tool which allows a user to interact with a graphical display of the inheritance tree. Finally, we optimize P#’s run-time speed by translating some Prolog predicates into more idiomatic C# code than is produced by a naive port of Prolog Cafe. This is achieved by observing that semi-deterministic predicates (being those which always either fail or succeed with exactly one solution) that only call other semi-deterministic predicates enjoy relatively simple control flow. We make use of the fact that Prolog programs often contain predicates which operate as functions, and that such predicates are usually semi-deterministic.

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

[2]  Andrew D. Gordon,et al.  Typing a multi-language intermediate code , 2001, POPL '01.

[3]  Nick Benton,et al.  Compiling standard ML to Java bytecodes , 1998, ICFP '98.

[4]  Nick Benton,et al.  Interlanguage working without tears: blending SML with Java , 1999, ICFP '99.

[5]  Patrick Lincoln,et al.  Linear logic , 1992, SIGA.

[6]  Manuel V. Hermenegildo,et al.  Using Attributed Variables in the Implementation of Concurrent and Parallel Logic Programming Systems , 1995, ICLP.

[7]  Chris Verhoef,et al.  The Realities of Language Conversions , 2000, IEEE Softw..

[8]  Ulrich Neumerkel,et al.  The Vienna Abstract Machine , 1990, PLILP.

[9]  Martin Odersky,et al.  A Nominal Theory of Objects with Dependent Types , 2003, ECOOP.

[10]  Guy L. Steele,et al.  The Java Language Specification , 1996 .

[11]  C. A. R. Hoare,et al.  Communicating sequential processes , 1978, CACM.

[12]  Mats Carlsson,et al.  Parallel execution of prolog programs: a survey , 2001, TOPL.

[13]  John H. Hartman,et al.  Toba: Java for Applications - A Way Ahead of Time (WAT) Compiler , 1997, COOTS.

[14]  James Gosling The Java Language Specification - Second Edition , 2000 .

[15]  Fergus Henderson,et al.  Compiling Mercury to High-Level C Code , 2002, CC.

[16]  John Gough,et al.  Technical Overview of the Common Language Runtime , 2001 .

[17]  Philippe Codognet,et al.  WAMCC: Compiling Prolog to C , 1995, ICLP.

[18]  Juliana Freire,et al.  Beyond Depth-First Strategies: Improving Tabled Logic Programs through Alternative Scheduling , 1998, J. Funct. Log. Program..

[19]  Jean-Yves Girard,et al.  Linear logic: its syntax and semantics , 1995 .

[20]  Simon L. Peyton Jones,et al.  Calling hell from heaven and heaven from hell , 1999, ICFP '99.

[21]  Naoyuki Tamura,et al.  Efficient Implementation of a Linear Logic Programming Language , 1998, IJCSLP.

[22]  Cornelia Pusch,et al.  Verification of Compiler Correctness for the WAM , 1996, TPHOLs.

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

[24]  Thuan L. Thai,et al.  NET framework essentials , 2001 .

[25]  John H. Reppy,et al.  Concurrent programming in ML , 1999 .

[26]  Jonathan J. Cook Optimizing P # : Translating Prolog to More Idiomatic C # , 2004 .

[27]  Steve Gregory,et al.  Parallel logic programming in PARLOG - the language and its implementation , 1987 .

[28]  David S. Platt,et al.  Introducing Microsoft® .NET , 2001 .

[29]  Manuel V. Hermenegildo,et al.  Concurrency in Prolog Using Threads and a Shared Database , 1999, ICLP.

[30]  Paul Tarau,et al.  Elementary Logic Programs , 1990, PLILP.

[31]  Werner Hans,et al.  A Complete Indexing Scheme for WAM-based Abstract Machines , 1992, PLILP.

[32]  Hassan Aït-Kaci,et al.  Warren's Abstract Machine: A Tutorial Reconstruction , 1991 .

[33]  Jonathan J. Cook,et al.  P#: a concurrent Prolog for the .NET framework , 2004, Softw. Pract. Exp..

[34]  Nick Benton,et al.  Adventures in interoperability: the SML.NET experience , 2004, PPDP '04.

[35]  Mutsunori Banbara,et al.  Compiling Resources in a Linear Logic Programming Language , 1998, Implementation Technology for Programming Languages based on Logic.

[36]  Jonathan J. Cook Reverse Execution of Java Bytecode , 2002, Comput. J..

[37]  Peter Ross,et al.  Making Mercury Programs Tail Recursive , 1999, LOPSTR.

[38]  Grady Booch,et al.  Essential COM , 1998 .

[39]  Jesse Liberty,et al.  Programming C , 2001 .

[40]  Andrew Kennedy Drawing Trees , 1996, J. Funct. Program..

[41]  Paolo Ciancarini,et al.  Parallel Programming with Logic Languages: A Survey , 1992, Comput. Lang..

[42]  John A. Campbell,et al.  Implementations of Prolog. , 1984 .

[43]  Xining Li Program Sharing: A New Implementation Approach for Prolog , 1996, PLILP.

[44]  William F. Clocksin,et al.  Programming in Prolog , 1987, Springer Berlin Heidelberg.

[45]  R. Kent Dybvig,et al.  The Scheme Programming Language , 1995 .

[46]  Mats Carlsson,et al.  SICStus MT - A Multithreaded Execution Environment for SICStus Prolog , 1998, PLILP/ALP.

[47]  Frank Yellin,et al.  The Java Virtual Machine Specification , 1996 .

[48]  Peter J. Stuckey,et al.  To the Gates of HAL: A HAL Tutorial , 2002, FLOPS.

[49]  Rob Gordon,et al.  Essential Jni: Java Native Interface , 1998 .

[50]  James S. Miller,et al.  Technical Overview of the Common Language Runtime (or why the JVM is not my favorite execution environment) , 2001 .

[51]  James Gosling,et al.  The Java Language Specification, 3rd Edition , 2005 .

[52]  Alan Pope,et al.  The CORBA reference guide - understanding the common object request broker architecture , 1998 .

[53]  Gary Roberts An implementation of prolog , 1977 .

[54]  Naoyuki Tamura,et al.  Extension of WAM for a linear logic programming language , 2007 .

[55]  Mutsunori Banbara,et al.  Translating a Linear Logic Programming Language into Java , 1999, Electron. Notes Theor. Comput. Sci..

[56]  Luís Moniz Pereira,et al.  Delta-Prolog: A Distributed Logic Programming Language , 1984, FGCS.

[57]  Evan Tick,et al.  The Deevolution of Concurrent Logic Programming Languages , 1995, J. Log. Program..

[58]  Andreas Krall,et al.  Fast Prolog with VAM1p based Prolog Compiler , 1992, PLILP.

[59]  Naoyuki Tamura,et al.  A COMPILER SYSTEM OF A LINEAR LOGIC PROGRAMMING LANGUAGE , 2003 .

[60]  田中 二郎 Ehud Shapiro 編, "Concurrent Prolog: Collected Papers" (コンカレント・プロログ論文集) The MIT Press, Vol.1, 525p., Vol.2, 653p., B5変形判 (縦23.5cm,横18.5cm) , 1988 .

[61]  Roberto Bagnara Foreign Language Interfaces for Prolog: A Terse Survey , 2002 .

[62]  Ehud Shapiro,et al.  Concurrent PROLOG: Collected Papers , 1987 .

[63]  Bjarne Stroustrup,et al.  C++ Programming Language , 1986, IEEE Softw..

[64]  John A. Campbell Implementation of PROLOG , 1984 .

[65]  Robin Milner,et al.  Definition of standard ML , 1990 .