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