| Logtalk | |
|---|---|
| Paradigm | Logic programming,object-oriented programming,prototype-based programming |
| Designed by | Paulo Moura |
| First appeared | 1998; 28 years ago (1998) |
| Stable release | 3.66.0 / 30 May 2023; 2 years ago (2023-05-30) |
| OS | Cross-platform |
| License | Artistic License 2.0 (2.x) /Apache License 2.0 (3.01.x) |
| Website | logtalk |
| Influenced by | |
| Prolog,Smalltalk,Objective-C | |
Logtalk is anobject-orientedlogic programming language that extends and leverages theProlog language with a feature set suitable forprogramming in the large.[1] It provides support forencapsulation and data hiding,separation of concerns and enhancedcode reuse.[1] Logtalk uses standard Prolog syntax with the addition of a few operators and directives.
The Logtalk language implementation is distributed under anopen source license and can run using a Prolog implementation (compliant with official and de facto standards)[1] as theback-end compiler.
Logtalk aims to bring together the advantages of object-oriented programming and logic programming.[1] Object-orientation emphasizes developing discrete, reusable units of software, while logic programming emphasizes representing the knowledge of each object in a declarative way.
As an object-oriented programming language, Logtalk's major features include support for bothclasses (with optionalmetaclasses) andprototypes, parametric objects,[2]protocols (interfaces), categories (components,aspects,hot patching),multiple inheritance, public/protected/private inheritance,event-driven programming, high-level multi-threading programming,[3]reflection, and automatic generation of documentation.
For Prolog programmers, Logtalk provides wide portability, featuring predicatenamespaces (supporting both static and dynamic objects), public/protected/private object predicates,coinductive predicates, separation between interface and implementation, simple and intuitive meta-predicate semantics,lambda expressions,definite clause grammars, term-expansion mechanism, and conditional compilation. It also provides a module system based on de facto standard core module functionality (internally, modules are compiled as prototypes).
Logtalk's syntax is based on Prolog:
?-write('Hello world'),nl.Hello worldtrue.
Defining an object:
:-object(my_first_object). :-initialization((write('Hello world'),nl)). :-public(p1/0). p1:-write('This is a public predicate'),nl. :-private(p2/0). p2:-write('This is a private predicate'),nl.:-end_object.
Using the object, assuming is saved in a my_first_object.lgt file:
?-logtalk_load(my_first_object).Hello worldtrue.?- my_first_object::p1.Thisis a public predicatetrue.
Trying to access the private predicate gives an error:
?- my_first_object::p2.ERROR: error(permission_error(access, private_predicate, p2), my_first_object::p2, user)
Logtalk uses the following syntax for anonymous predicates (lambda expressions):
{FreeVar1,FreeVar2, ...}/[LambdaParameter1,LambdaParameter2, ...]>>Goal
A simple example with no free variables and using a list mapping predicate is:
|?- meta::map([X,Y]>>(Yis2*X), [1,2,3],Ys).Ys= [2,4,6]yes
Currying is also supported. The above example can be written as:
|?- meta::map([X]>>([Y]>>(Yis2*X)), [1,2,3],Ys).Ys= [2,4,6]yes
Supported back-end Prolog compilers includeB-Prolog,Ciao Prolog, CxProlog,ECLiPSe,GNU Prolog, JIProlog,Quintus Prolog, Scryer Prolog,SICStus Prolog,SWI-Prolog, Tau Prolog, Trealla Prolog,XSB, andYAP.[4] Logtalk allows use of back-end Prolog compiler libraries from within object and categories.
Logtalk features on-line help, a documenting tool (that can generate PDF and HTML files), an entity diagram generator tool, a built-in debugger (based on an extended version of the traditional Procedure Box model found on most Prolog compilers), a unit test framework with code coverage analysis, and is also compatible with selected back-end Prolog profilers and graphical tracers.[5]
Logtalk has been used to processSTEP data models used to exchangeproduct manufacturing information.[6] It has also been used to implement a reasoning system that allows preference reasoning andconstraint solving.[7]