{{Infobox programming language |name = Logtalk |paradigm = Logic programming, object-oriented programming, prototype-based programming |year = {{Start date and age|1998}} |typing = |designer = Paulo Moura |latest release version = 3.66.0 |latest release date = {{Start date and age|2023|05|30|df=yes}} |implementations = |operating_system = Cross-platform |license = Artistic License 2.0 (2.x) / Apache License 2.0 (3.01.x) |dialects = |influenced_by = Prolog, Smalltalk, Objective-C |influenced = |website = {{URL|//logtalk.org}} }}
'''Logtalk''' is an object-oriented logic programming language that extends and leverages the Prolog language with a feature set suitable for programming in the large.<ref name="moura 2003">Paulo Moura (2003). Logtalk: Design of an Object-Oriented Logic Programming Language. PhD thesis. Universidade da Beira Interior</ref> It provides support for encapsulation and data hiding, separation of concerns and enhanced code reuse.<ref name="moura 2003" /> Logtalk uses standard Prolog syntax with the addition of a few operators and directives.
The Logtalk language implementation is distributed under an open source license and can run using a Prolog implementation (compliant with official and de facto standards)<ref name="moura 2003" /> as the back-end compiler.
==Features== Logtalk aims to bring together the advantages of object-oriented programming and logic programming.<ref name="moura 2003" /> 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 both classes (with optional metaclasses) and prototypes, parametric objects,<ref>{{Cite conference | doi = 10.1007/978-3-642-20589-7_4| title = Programming Patterns for Logtalk Parametric Objects| conference = Applications of Declarative Programming and Knowledge Management| volume = 6547| series = Lecture Notes in Computer Science| year = 2011| last1 = Moura | first1 = Paulo| isbn = 978-3-642-20588-0}}</ref> protocols (interfaces), categories (components, aspects, hot patching), multiple inheritance, public/protected/private inheritance, event-driven programming, high-level multi-threading programming,<ref>{{Cite book | doi = 10.1007/978-3-540-77442-6| title = Practical Aspects of Declarative Languages| volume = 4902| series = Lecture Notes in Computer Science| year = 2008| isbn = 978-3-540-77441-9}}</ref> reflection, and automatic generation of documentation.
For Prolog programmers, Logtalk provides wide portability, featuring predicate namespaces (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).
==Examples== Logtalk's syntax is based on Prolog: <syntaxhighlight lang="logtalk"> ?- write('Hello world'), nl. Hello world true. </syntaxhighlight>
Defining an object: <syntaxhighlight lang="logtalk"> :- 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. </syntaxhighlight>
Using the object, assuming is saved in a my_first_object.lgt file: <syntaxhighlight lang="logtalk"> ?- logtalk_load(my_first_object). Hello world true.
?- my_first_object::p1. This is a public predicate true. </syntaxhighlight>
Trying to access the private predicate gives an error: <syntaxhighlight lang="logtalk"> ?- my_first_object::p2. ERROR: error(permission_error(access, private_predicate, p2), my_first_object::p2, user) </syntaxhighlight> === Anonymous functions === {{excerpt|Examples of anonymous functions#Logtalk}}
==Prolog back-end compatibility== Supported back-end Prolog compilers include B-Prolog, Ciao Prolog, CxProlog, ECLiPSe, GNU Prolog, JIProlog, Quintus Prolog, Scryer Prolog, SICStus Prolog, SWI-Prolog, Tau Prolog, Trealla Prolog, XSB, and YAP.<ref>{{cite web|url=http://logtalk.org/compatibility.html |title=Logtalk compatibility |publisher=Logtalk.org |date=2016-10-10 |accessdate=2021-07-06}}</ref> Logtalk allows use of back-end Prolog compiler libraries from within object and categories.
==Developer tools== 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.<ref>{{cite web|author= |url=https://github.com/LogtalkDotOrg/logtalk3/wiki/Developer-Tools |title=Developer Tools – LogtalkDotOrg/logtalk3 Wiki – GitHub |publisher=Github.com |date=2013-02-12 |accessdate=2013-08-19}}</ref>
==Applications== Logtalk has been used to process STEP data models used to exchange product manufacturing information.<ref>{{Cite book | doi = 10.1007/11799573| title = Logic Programming| volume = 4079| series = Lecture Notes in Computer Science| year = 2006| isbn = 978-3-540-36635-5}}</ref> It has also been used to implement a reasoning system that allows preference reasoning and constraint solving.<ref>{{ cite conference | conference = Logic Programming and Nonmonotonic Reasoning | series = Lecture Notes in Computer Science | year = 2009 | volume= 5753 | pages = 535–541 | url=ftp://ftp.irit.fr/IRIT/SMAC/DOCUMENTS/PUBLIS/lpnmr-09_noel-kakas.pdf | title = Gorgias-C: Extending Argumentation with Constraint Solving | author1 = Victor Noël | author2 = Antonis Kakas }}</ref>
==See also== * Mercury (programming language) * Oz (programming language) * Prolog++ * Visual Prolog * Comparison of Prolog implementations * Prolog syntax and semantics
==References== {{Reflist}}
==External links== *{{official website|//logtalk.org}} *[https://logtalk.org/blog.html Logtalking blog] *From Plain Prolog to Logtalk Objects: Effective Code Encapsulation and Reuse (Invited Talk). Paulo Moura. Proceedings of the 25th International Conference on Logic Programming (ICLP), July 2009. LNCS 5649. Springer-Verlag Berlin Heidelberg". ([http://logtalk.org/papers/iclp2009/logtalk_iclp2009.pdf Slides])
Category:Object-oriented programming languages Category:Prolog programming language family