The Logtalk Handbook Release V3.22.0
Total Page:16
File Type:pdf, Size:1020Kb
The Logtalk Handbook Release v3.22.0 Paulo Moura Dec 18, 2018 CONTENTS: 1 User Manual 1 1.1 Declarative object-oriented programming.............................1 1.2 Main features.............................................2 1.2.1 Integration of logic and object-oriented programming..................2 1.2.2 Integration of event-driven and object-oriented programming.............2 1.2.3 Support for component-based programming.......................2 1.2.4 Support for both prototype and class-based systems...................3 1.2.5 Support for multiple object hierarchies..........................3 1.2.6 Separation between interface and implementation....................3 1.2.7 Private, protected and public inheritance.........................3 1.2.8 Private, protected and public object predicates......................3 1.2.9 Parametric objects.....................................3 1.2.10 High level multi-threading programming support....................4 1.2.11 Smooth learning curve...................................4 1.2.12 Compatibility with most Prolog systems and the ISO standard.............4 1.2.13 Performance.........................................4 1.2.14 Logtalk scope........................................4 1.3 Nomenclature............................................5 1.3.1 C++ nomenclature.....................................5 1.3.2 Java nomenclature.....................................6 1.4 Messages...............................................7 1.4.1 Operators used in message sending............................7 1.4.2 Sending a message to an object..............................8 1.4.3 Delegating a message to an object.............................8 1.4.4 Sending a message to self .................................8 1.4.5 Broadcasting........................................8 1.4.6 Calling imported and inherited predicates........................9 1.4.7 Message sending and event generation..........................9 1.5 Objects................................................ 10 1.5.1 Objects, prototypes, classes, and instances........................ 10 1.5.2 Defining a new object.................................... 11 1.5.3 Parametric objects..................................... 13 1.5.4 Finding defined objects................................... 14 1.5.5 Creating a new object in runtime............................. 14 1.5.6 Abolishing an existing object................................ 15 1.5.7 Object directives...................................... 15 1.5.8 Object relationships..................................... 17 1.5.9 Object properties...................................... 18 1.5.10 Built-in objects....................................... 20 1.6 Protocols............................................... 21 i 1.6.1 Defining a new protocol.................................. 21 1.6.2 Finding defined protocols................................. 22 1.6.3 Creating a new protocol in runtime............................ 22 1.6.4 Abolishing an existing protocol.............................. 22 1.6.5 Protocol directives..................................... 23 1.6.6 Protocol relationships.................................... 23 1.6.7 Protocol properties..................................... 24 1.6.8 Implementing protocols.................................. 24 1.6.9 Built-in protocols...................................... 25 1.7 Categories.............................................. 26 1.7.1 Defining a new category.................................. 26 1.7.2 Finding defined categories................................. 28 1.7.3 Creating a new category in runtime............................ 29 1.7.4 Abolishing an existing category.............................. 29 1.7.5 Category directives..................................... 29 1.7.6 Category relationships................................... 30 1.7.7 Category properties..................................... 31 1.7.8 Importing categories.................................... 32 1.7.9 Calling category predicates................................. 33 1.7.10 Parametric categories.................................... 34 1.8 Predicates............................................... 34 1.8.1 Reserved predicate names................................. 34 1.8.2 Declaring predicates.................................... 34 1.8.3 Defining predicates..................................... 42 1.8.4 Built-in object predicates (methods)............................ 47 1.8.5 Predicate properties..................................... 51 1.8.6 Finding declared predicates................................ 52 1.8.7 Calling Prolog predicates.................................. 52 1.9 Inheritance.............................................. 55 1.9.1 Protocol inheritance.................................... 55 1.9.2 Implementation inheritance................................ 55 1.9.3 Public, protected, and private inheritance......................... 58 1.9.4 Composition versus multiple inheritance......................... 59 1.10 Event-driven programming..................................... 60 1.10.1 Definitions.......................................... 60 1.10.2 Event generation...................................... 61 1.10.3 Communicating events to monitors............................ 61 1.10.4 Performance concerns................................... 61 1.10.5 Monitor semantics..................................... 61 1.10.6 Activation order of monitors................................ 62 1.10.7 Event handling....................................... 62 1.11 Multi-threading programming................................... 64 1.11.1 Enabling multi-threading support............................. 64 1.11.2 Enabling objects to make multi-threading calls...................... 64 1.11.3 Multi-threading built-in predicates............................ 65 1.11.4 One-way asynchronous calls................................ 67 1.11.5 Asynchronous calls and synchronized predicates..................... 67 1.11.6 Synchronizing threads through notifications....................... 69 1.11.7 Threaded engines...................................... 69 1.11.8 Multi-threading performance............................... 70 1.12 Error handling............................................ 71 1.12.1 Compiler warnings and errors............................... 71 1.12.2 Runtime errors....................................... 73 1.13 Writing and running applications.................................. 74 ii 1.13.1 Writing applications.................................... 74 1.13.2 Compiling and running applications............................ 76 1.14 Printing messages and asking questions.............................. 84 1.14.1 Printing messages...................................... 85 1.14.2 Message tokenization.................................... 86 1.14.3 Intercepting messages................................... 86 1.14.4 Asking questions...................................... 87 1.14.5 Intercepting questions................................... 88 1.15 Term and goal expansion...................................... 88 1.15.1 Defining expansions.................................... 89 1.15.2 Expanding grammar rules................................. 90 1.15.3 Hook objects........................................ 90 1.15.4 Bypassing expansions.................................... 91 1.15.5 Combining multiple expansions.............................. 91 1.15.6 Using Prolog defined expansions.............................. 91 1.16 Documenting............................................. 91 1.16.1 Documenting directives.................................. 92 1.16.2 Processing and viewing documenting files........................ 94 1.16.3 Inline formatting in comments text............................ 94 1.16.4 Diagrams.......................................... 94 1.17 Debugging.............................................. 95 1.17.1 Compiling source files in debug mode........................... 95 1.17.2 Procedure Box model.................................... 95 1.17.3 Defining spy points..................................... 97 1.17.4 Tracing program execution................................. 98 1.17.5 Debugging using spy points................................ 99 1.17.6 Debugging commands................................... 99 1.17.7 Context-switching calls................................... 100 1.17.8 Using compilation hooks and term expansion for debugging.............. 101 1.17.9 Debugging messages.................................... 101 1.17.10 Ports profiling........................................ 102 1.18 Performance............................................. 102 1.18.1 Local predicate calls.................................... 103 1.18.2 Calls to imported or inherited predicates......................... 103 1.18.3 Calls to module predicates................................. 103 1.18.4 Messages.......................................... 103 1.18.5 Inlining........................................... 103 1.18.6 Generated code simplification and optimizations..................... 103 1.18.7 Other considerations.................................... 104 1.19 Installing Logtalk........................................... 104 1.19.1 Hardware and software requirements........................... 104 1.19.2 Logtalk installers...................................... 105 1.19.3 Source distribution..................................... 105 1.19.4 Distribution overview.................................... 105 1.20 Prolog integration and migration guide.............................. 109 1.20.1 Source files