The Gödel Programming Language

The Gödel Programming Language

The G¨odel Programming Language P.M. Hill1 and J.W. Lloyd October 1992 CSTR-92-27 (Revised May 1993) Department of Computer Science University of Bristol University Walk Bristol BS8 1TR c P.M. Hill and J.W. Lloyd 1992 1School of Computer Studies, University of Leeds, Leeds, LS2 9JT Preface Would that I had unknown utterances and strange phrases, In a new language that does not pass away, Free from repetition, Without a phrase of familiar speech which the ancestors spoke. From The Words of Khakheperreseneb, around 1890 B.C. G¨odel is a declarative, general-purpose programming language in the family of logic program- ming languages. It is a strongly typed language, the type system being based on many-sorted logic with parametric polymorphism. It has a module system. G¨odel supports infinite precision integers, infinite precision rationals, and also floating-point numbers. It can solve constraints over finite domains of integers and also linear rational constraints. It supports processing of finite sets. It also has a flexible computation rule and a pruning operator which generalises the commit of the concurrent logic programming languages. Considerable emphasis is placed on G¨odel’s meta-logical facilities which provide significant support for meta-programs that do analysis, transformation, compilation, verification, debugging, and so on. The declarative nature of G¨odel makes it par- ticularly suitable for use as a teaching language; narrows the gap which currently exists between theory and practice in logic programming; makes possible advanced software engineering tools such as declarative debuggers and compiler generators; reduces the effort involved in providing a parallel implementation of the language; and offers substantial scope for parallelization in such implementations. This book describes the G¨odel language and is divided into two parts. The first part gives an informal overview of the language and includes example programs. The second part contains a definition of the syntax and semantics of the language. We assume readers have some program- ming experience, have some acquaintance with logic programming concepts, and are familiar with the most basic material on the syntax and semantics of first order logic. We provide an appendix on polymorphic many-sorted logic for readers not familiar with this generalisation of (unsorted) first order logic. At the end of the first chapter, we give, for those familiar with Prolog, a compari- son between G¨odel and Prolog. This provides much of the motivation for G¨odel and explains why various design decisions were taken. We suggest readers follow the first nine chapters in order, looking ahead to the example programs in chapter 10 and referring to the formal definitions in the second part, as appropriate. Augmented by the reference manual of a particular implementation, the book contains everything a programmer needs to know to write large-scale G¨odel programs. Readers will notice that little is said about the procedural semantics of G¨odel in this book. This is a decision which probably requires some explanation, since one might expect a book which gives a formal definition of a programming language to be rather precise on this point. First, for the syntax and declarative semantics, we have tried to be precise and comprehensive. The main criticism that could be made of our description of the declarative semantics is that the specification of the system predicates is given in English rather than some formal language. Our chosen method achieves conciseness, but at the expense of some lack of precision. In contrast, for the procedural semantics, we have adopted a different approach and merely specified that the implementation be sound and satisfy some other conditions. (For example, the conditions under ii which a DELAY declaration will delay a call are specified, as is the pruning effect of the commit operator.) The main advantage of specifying the procedural semantics in great detail is portability, so that one could port a program from one implementation to another and be confident of identical behaviour of the program in the two systems. In spite of this, we have decided not to follow this approach. The reason is that logic programming language implementation is currently in a state of rapid development, so that whatever precise procedural semantics we might specify now is likely to look outdated and unnecessarily conservative in a couple of years. By leaving the details of the procedural semantics so open, we hope to encourage, or at least not impede, this development. This approach gives implementors of G¨odel considerable freedom and, for example, admits theorem proving methods which provide a more flexible handling of negation than the usual SLDNF-resolution. However, the reference manual of an implementation will need to discuss whatever further details on the procedural semantics are required to write (reasonably) efficient programs. The most likely difference between implementations of G¨odel will be that programs terminat- ing on one implementation may flounder on another. The two places where this is most likely to happen are with constraint solving and the handling of negation. This is because a considerable range of sophistication of constraint solvers for the integers and rationals is possible. Also, an implementation employing safe negation may flounder on calls which would run on an imple- mentation employing a more flexible implementation of negation. However, only completeness is affected: all implementations must be sound. It is hardly possible to design a new programming language without relying to a great extent on previous work. G¨odel is no exception to this. First, we owe an indirect debt to Alain Colmerauer who designed the first Prolog language, many features of which are clearly evident in G¨odel. We have also borrowed good ideas from more recent logic programming languages. In particular, we have adopted the if-then-else construct and the when declarations of NU-Prolog. Both of these facilities are due to Lee Naish. We drew inspiration from languages, such as ML and Modula-2, which demonstrate the clear necessity and value of type systems and module systems. We owe a particular debt to Antony Bowers and Jiwei Wang, who have undertaken so success- fully the substantial and demanding task of implementing the language. Corin Gurr helped with the implementation of the meta-programming modules. Also his work on self-applicable partial evaluators influenced the design of the language. Antony Bowers contributed to the design, es- pecially of the meta-programming facilities, and introduced the concept of type lifting. Alistair Burt, who spent 12 months on the project, produced the first implementation of a subset of the language and also contributed to its design, especially the idea that the ground representation used by the meta-programming facilities should be handled like an abstract data type. Andrea Domenici contributed to an early implementation of the parser. Frank Defoort experimented at a formative stage with writing interpreters using the ground representation. Various people commented on drafts of this book. These include Antony Bowers, Frank Defoort, Andrea Domenici, John Gallagher, Corin Gurr, Feliks Kluzniak, Micha Meier, Lee Naish, Vitor Santos Costa, Jeffrey Schultz, Zoltan Somogyi, Rodney Topor, and Jiwei Wang. The first author is indebted to the Division of Artificial Intelligence (and in particular Tony Cohn) at the University of Leeds for encouraging her work on G¨odel. The second author would like to thank many people, too numerous to mention, for many interesting discussions over the last decade, which have helped shape the form that G¨odel has finally taken. iii We are also indebted to Dr. Richard Parkinson of the Department of Egyptian Antiquities at the British Museum for the use of his translation of the above passage from the Words of Khakheperreseneb, which is preserved on a wooden writing tablet dating from the 18th Dynasty and is now in the British Museum (EA 5645). Khakheperreseneb is said to have been a priest of the city of Heliopolis. His name indicates that the text cannot predate the reign of Sesostris II (1895–1878 B.C.) in the Late Middle Kingdom. The design and implementation of G¨odel was partly supported by the ESPRIT Basic Re- search Action 3012 (Compulog) and Project 6810 (Compulog 2), SERC Grants GR/F/26256 and GR/H/79862, the University of Bristol, and the University of Leeds. For details on obtaining an implementation of G¨odel by ftp, send a message to [email protected] May 1993 PMH JWL Contents I Overview of G¨odel 1 1 Introduction 3 1.1 Declarative Programming ............................... 3 1.2 G¨odel Facilities .................................... 4 1.3 Comparison with Prolog ............................... 9 2 Types 15 2.1 Many-Sortedness .................................... 15 2.2 Polymorphism ..................................... 18 3 Formulas 23 3.1 Quantifiers and Connectives ............................. 23 3.2 Conditionals ...................................... 25 3.3 Operators ........................................ 28 4 Equality and Numbers 31 4.1 Equality ........................................ 31 4.2 Integers ........................................ 33 4.3 Rationals ....................................... 36 4.4 Floats ......................................... 38 4.5 Numbers ........................................ 40 5 Modules 41 5.1 Importing and Exporting ............................... 41 5.2 Module Declarations

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    297 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us