A Parlog Object Oriented Language
Total Page:16
File Type:pdf, Size:1020Kb
Polka : A Parlog Object Oriented Language. Andrew Davison A thesis submitted to the University of London for the degree of Doctor of Philosophy Department of Computing Imperial College of Science, Technology and Medicine September 1989 2 Abstract Programming language design is an evolutionary process. For instance, the concurrent Logic Programming (LP) paradigm and its associated languages could not have been developed without the work on LP and on models of concurrency during the last decade. This evolution is clearly visible in Polka which is, first and foremost, a language derived from the fusion of the concurrent LP and Object Oriented Programming (OOP) paradigms. The result is more than a sum of its parts since many of the inadequacies of one programming model are compensated for by features of the other. One of the other design goals behind Polka is its utilisation as a ‘higher level’ concurrent LP language. This is possible because Polka contains abstractions which are well suited to programming typical kinds of concurrent LP problems. The last design goal is the incorporation of meta level programming concepts from LP into Polka, which greatly increase the functionality of the class mechanism. This thesis presents the background to, and motivation for, the design of Polka, and describes the language. The utility of Polka is demonstrated through numerous small examples, and three larger applications concerned with graphics, blackboard problem solving, and simulation. Also, an operational semantics is developed for a subset of the language, called kernel Polka, and a simple and efficient implementation is derived from it 3 Acknowledgments I am, of course, greatly indebted to my supervisor Keith Clark, who has encouraged my work, and dispensed invaluable advice. In addition, his comments on this thesis have been consistently useful and enlightening. Most of all, I thank him for his friendship. I must also thank a number of people who read earlier drafts of the thesis, and supplied extremely informative comments. They are (in no particular order) : Alastair Burt, Melissa Lam, Colin Atkinson, Ian Foster, Gul Agha, and Ken Kahn. The working environment has been excellent, and this must be attributed to my fellow members in the Parlog Group, some of whom have now left for pastures new. Apart from those already mentioned, I must thank (again in no particular order): Steve Gregory, Graem Ringwood, Jim Crammond, Matthew Huntbach, Reem Bahgat, David Gilbert, Bob Kemp, Fukumi Kozato, Priscila Lima, and numerous Parlog Group secretaries. The Parlog Group is only a small part of the larger Logic Programming section, and friends and colleagues in the section have made my time at Imperial very happy. There being too many people to mention, I simply thank Bob Kowalski and Cheryl Anderson. My research has been supported by the Science and Engineering Research Council. Other recent work on Polka at Imperial College has been funded by various research grants. 4 Contents Part 1. Introductory Material. 16 1. Introduction. 17 1.1 The Context of the Research : Language Design. 17 1.2 Contributions of the Thesis. 18 1.3 Assumptions about the Readership. 19 1.4 Preview of the Contents. 19 2. Logic Programming Overview. 21 2.1 Logic Programming. 21 2.2 Concurrent Logic Programming. 22 2.3 Parlog..................................................................................................... 23 2.3.1 The Process Interpretation in Parlog. 25 2.3.2 The Control Metacall. 29 2.3.3 Semantics of Parlog. 29 3. Design Issues for LP-based Object Oriented Languages. 31 3.1 Motivation for combining OOP and LP. 32 3.1.1 The reasons for adding OOP to LP. 32 3.1.2 The reasons for adding LP to OOP......................................33 3.1.3 Applications. 33 3.2 Object and Class Representation. 34 3.2.1 The ADT View of Objects and Classes...............................35 3.2.2 The Theory View of Objects and Classes. 37 3.2.3 The Process View of Objects and Classes. 37 3.2.3.1 The Committed Choice Process View ..................... 37 3.2.3.2 The Backtracking Process View. 40 3.3 Message Passing. 41 3.3.1 Message Passing in the ADT View.................................. 42 3.3.2 Message Passing in the Theory View. 44 3.3.3 Message Passing in the Process View. 44 3.3.3.1 Message Passing in the CCPV ................................... 44 3.3.3.2 Message Passing in the Backtracking Process View.47 3.3.3.2.1 Wait Declarations. 47 3.3.3.2.2 Events. 48 3.3.3.2.3 D-clauses. 49 3.4 State. 51 3.4.1 State in the ADT View ........................................................ 51 3.4.2 State in the Theory View. 52 3.4.3 State in the Process View. 52 3.4.3.1 State in the Committed Choice Process View ...........53 3.4.3.2 State in the Backtracking Process View. 53 3.5 Inheritance. 54 3.5.1 Inheritance in the ADT View..............................................55 3.5.2 Inheritance in the Theory View. 59 3.5.3 Inheritance in the Process View. 59 3.5.3.1 Inheritance in the Committed Choice Process View. 59 3.5.3.2 Inheritance in the Backtracking Process View. 61 3.6 Other Paradigms. 62 3.6.1 Other Paradigms in the ADT View....................................62 3.6.2 Other Paradigms in the Theory View. 63 3.6.3 Other Paradigms in the Process View. 63 3.7 Summary of the Views ............................................... V 7 '. ............. 63 3.7.1 Summary of the ADT View. 63 3.7.2 Summary of the Theory View. .. 64 3.7.3 Summary of the Process View.............................................64 3.7.3.1 Summary of the Committed Choice Process View. 64 3.7.3.2 Summary of the Backtracking Process View. 65 4. An Overview of Polka. 66 4.1 Polka Features. 66 4.2 The Advantages of Polka. 68 4.3 The Disadvantages of Polka. 68 Part 2. Language and Applications. 71 5. The Language. 7 2 5.1 Class Structure. 72 5.1.1 A 'receiver' Class. 73 5.1.2 A'filestore'Class. 74 5.2 Default Polka Clauses. 77 6 5.3 Variables. 78 5.4 The initial Section. 79 5.5 Clauses................................................................................................... 80 5.6 Input Messages. 81 5.7 Becomes. 83 5.8 Output Messages.................................................................................. 84 5.9 I_am. 85 5.10 The code Section. 87 5.11 Inheritance...........................................................................................88 5.12 Self Communication. 99 5.13 ‘Higher level’ Parlog. 101 6. Meta Level Programming. 104 6.1 What is Meta Level Programming? 104 6.2 The Uses of Meta Level Programming. 107 6.3 Program Transformation...................................................................108 6.4 Load Balancing. 112 6.5 Parametrised Classes. 114 6.6 Extensible Classes..............................................................................117 6.6.1 Computer. 119 6.6.2 Square. 119 6.6.3 Circle.................................................................................... 120 6.6.4 Window. 121 6.6.5 Support Classes. 122 7. Three Examples. 127 7.1 Graphics. 127 7.1.1 Overview of the Classes. 127 7.1.2 Screen................................................................................. 128 7.1.3 Shape. 131 7.1.4 Turtle. 134 7.1.5 The Parlog Approach ........................................................... 137 7.1.6 Possible Changes to the Programs. 140 7.2 Blackboard Systems. 142 7.2.1 Background to Blackboard Systems ..................................142 7.2.1.1 The Blackboard. 143 7.2.1.2 Knowledge Sources (KSs). 143 7 7.2.1.3 Control. 143 7.2.1.4 Parallelism Issues. 144 7.2.1.5 Manipulation Issues .................................................... 145 7.2.2 Polka Blackboard Systems. 146 7.2.2.1 Polka Blackboards. 146 1.2.2.2 Polka KSs.....................................................................150 7.2.3 A Version of Hearsay H. 155 7.2.4 Summary of the Blackboard Example. 157 7.3 Simulation .......................................................................................... 158 7.3.1 Overview of Simulation. 158 7.3.1.1 Simulation in Logic Programming Languages. 158 7.3.2 Distributed Time ................................................................... 160 7.3.2.1 Distributed Time in Polka. 161 7.3.3 Polka Simulation Classes. 164 7.3.3.1 Random Number Generators .................................... 165 7.3.3.1.1 Uniform. 166 7.3.3.1.2 Randint. 166 13.3.2 Resources........................................................ 167 7.3.33 Report Generation. 170 7.3.4 Two Simulation Examples. / 171 7.3.4.1 A Car Wash..................................................................171 7.3.4.2 An Information Retrieval System. 173 7.3.5 Summary of the Simulation Example. 175 8. Concurrency. 176 8.1 What is Concurrency? 176 8.2 Synchronisation. 177 8.3 Rendezvous-like Synchronisation ................................................... 180 8.4 Liveness. 189 8.5 Arrival, Selection and Completion. 191 8.6 Separation of Synchronisation from Functionality........................192 8.6.1 The Readers-Writers Problem. 193 8.6.2 Readers Priority. 195 8.7 The Actor Model. 197 8 Part 3. Semantics and Implementation. 203 9. Kernel Polka. 204 9.1 Default Clauses. 204 9.2 Variables. 205 9.3 Input Messages.................................................................................205 9.4 Clauses. 205 9.5 Becomes. 205 9.6 Output Messages..............................................................................206 9.7 Inheritance. 207 9.8 The Parlog Component. 207 10. Semantics. 208 10.1 Transition Systems. 209 10.2 The Configuration. 210 10.2.1