The Logtalk Handbook Release V3.39.0
Total Page:16
File Type:pdf, Size:1020Kb
The Logtalk Handbook Release v3.39.0 Paulo Moura Jun 17, 2020 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.......................3 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......................4 1.2.9 Parametric objects.....................................4 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........................................5 1.3 Nomenclature............................................5 1.3.1 Smalltalk nomenclature..................................6 1.3.2 C++ nomenclature.....................................7 1.3.3 Java nomenclature.....................................8 1.3.4 Python nomenclature....................................9 1.4 Messages............................................... 10 1.4.1 Operators used in message sending............................ 11 1.4.2 Sending a message to an object.............................. 11 1.4.3 Delegating a message to an object............................. 11 1.4.4 Sending a message to self ................................. 11 1.4.5 Broadcasting........................................ 12 1.4.6 Calling imported and inherited predicates........................ 12 1.4.7 Message sending and event generation.......................... 12 1.4.8 Sending a message from a module............................ 13 1.4.9 Message sending performance............................... 13 1.5 Objects................................................ 13 1.5.1 Objects, prototypes, classes, and instances........................ 14 1.5.2 Defining a new object.................................... 14 1.5.3 Parametric objects..................................... 17 1.5.4 Finding defined objects................................... 18 1.5.5 Creating a new object in runtime............................. 18 1.5.6 Abolishing an existing object................................ 19 1.5.7 Object directives...................................... 19 i 1.5.8 Object relationships..................................... 21 1.5.9 Object properties...................................... 22 1.5.10 Built-in objects....................................... 24 1.6 Protocols............................................... 24 1.6.1 Defining a new protocol.................................. 24 1.6.2 Finding defined protocols................................. 25 1.6.3 Creating a new protocol in runtime............................ 25 1.6.4 Abolishing an existing protocol.............................. 26 1.6.5 Protocol directives..................................... 26 1.6.6 Protocol relationships.................................... 26 1.6.7 Protocol properties..................................... 27 1.6.8 Implementing protocols.................................. 28 1.6.9 Built-in protocols...................................... 28 1.7 Categories.............................................. 29 1.7.1 Defining a new category.................................. 29 1.7.2 Hot patching........................................ 31 1.7.3 Finding defined categories................................. 32 1.7.4 Creating a new category in runtime............................ 33 1.7.5 Abolishing an existing category.............................. 33 1.7.6 Category directives..................................... 34 1.7.7 Category relationships................................... 34 1.7.8 Category properties..................................... 35 1.7.9 Importing categories.................................... 37 1.7.10 Calling category predicates................................. 37 1.7.11 Parametric categories.................................... 38 1.7.12 Built-in categories...................................... 39 1.8 Predicates............................................... 39 1.8.1 Reserved predicate names................................. 39 1.8.2 Declaring predicates.................................... 39 1.8.3 Defining predicates..................................... 48 1.8.4 Definite clause grammar rules............................... 52 1.8.5 Built-in methods...................................... 55 1.8.6 Predicate properties..................................... 58 1.8.7 Finding declared predicates................................ 60 1.8.8 Calling Prolog predicates.................................. 60 1.8.9 Defining Prolog multifile predicates............................ 64 1.8.10 Asserting and retracting Prolog predicates........................ 64 1.9 Inheritance.............................................. 66 1.9.1 Protocol inheritance.................................... 66 1.9.2 Implementation inheritance................................ 66 1.9.3 Public, protected, and private inheritance......................... 69 1.9.4 Multiple inheritance.................................... 70 1.9.5 Composition versus multiple inheritance......................... 71 1.10 Event-driven programming..................................... 71 1.10.1 Definitions.......................................... 72 1.10.2 Event generation...................................... 73 1.10.3 Communicating events to monitors............................ 73 1.10.4 Performance concerns................................... 73 1.10.5 Monitor semantics..................................... 73 1.10.6 Activation order of monitors................................ 74 1.10.7 Event handling....................................... 74 1.11 Multi-threading programming................................... 76 1.11.1 Enabling multi-threading support............................. 76 1.11.2 Enabling objects to make multi-threading calls...................... 76 ii 1.11.3 Multi-threading built-in predicates............................ 77 1.11.4 One-way asynchronous calls................................ 79 1.11.5 Asynchronous calls and synchronized predicates..................... 79 1.11.6 Synchronizing threads through notifications....................... 81 1.11.7 Threaded engines...................................... 81 1.11.8 Multi-threading performance............................... 82 1.12 Error handling............................................ 83 1.12.1 Raising Exceptions..................................... 83 1.12.2 Type-checking........................................ 83 1.12.3 Expected terms....................................... 84 1.12.4 Compiler warnings and errors............................... 84 1.12.5 Runtime errors....................................... 87 1.13 Reflection............................................... 88 1.13.1 Structural reflection.................................... 88 1.13.2 Behavioral reflection.................................... 88 1.14 Writing and running applications.................................. 89 1.14.1 Starting Logtalk....................................... 89 1.14.2 Source files......................................... 90 1.14.3 Compiling and loading your applications......................... 91 1.14.4 Loader files......................................... 92 1.14.5 Libraries of source files................................... 93 1.14.6 Settings files......................................... 94 1.14.7 Compiler linter....................................... 95 1.14.8 Compiler flags........................................ 95 1.14.9 Reloading source files.................................... 100 1.14.10 Batch processing...................................... 101 1.14.11 Optimizing performance.................................. 101 1.14.12 Portable applications.................................... 101 1.14.13 Conditional compilation.................................. 102 1.14.14 Avoiding common errors.................................. 102 1.14.15 Coding style guidelines................................... 102 1.15 Printing messages and asking questions.............................. 102 1.15.1 Printing messages...................................... 103 1.15.2 Message tokenization.................................... 104 1.15.3 Meta-messages....................................... 105 1.15.4 Intercepting messages................................... 105 1.15.5 Asking questions...................................... 106 1.15.6 Intercepting questions................................... 107 1.16 Term and goal expansion...................................... 107 1.16.1 Defining expansions.................................... 108 1.16.2 Expanding grammar rules................................. 109 1.16.3 Bypassing expansions.................................... 109 1.16.4 Hook objects........................................ 110 1.16.5 Virtual source file terms and loading context....................... 110 1.16.6 Default compiler expansion workflow........................... 111 1.16.7 User defined expansion workflows............................