Logtalk

Last updated
Logtalk
Paradigm Logic programming, object-oriented programming, prototype-based programming
Designed by Paulo Moura
First appeared1998;26 years ago (1998)
Stable release
3.66.0 / 30 May 2023;17 months ago (2023-05-30)
OS Cross-platform
License Artistic License 2.0 (2.x) / Apache License 2.0 (3.01.x)
Website logtalk.org
Influenced by
Prolog, Smalltalk, Objective-C

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. [1] It provides support for encapsulation and data hiding, separation of concerns and enhanced code reuse. [1] Logtalk uses standard Prolog syntax with the addition of a few operators and directives.

Contents

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) [1] as the back-end compiler.

Features

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 both classes (with optional metaclasses) and prototypes, 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 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:

?-write('Hello world'), nl. Hello world true. 

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 world true.  ?- my_first_object::p1. Thisis a public predicate true. 

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) 

Anonymous functions

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 

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. [4] 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. [5]

Applications

Logtalk has been used to process STEP data models used to exchange product manufacturing information. [6] It has also been used to implement a reasoning system that allows preference reasoning and constraint solving. [7]

See also

Related Research Articles

Logic programming is a programming, database and knowledge representation paradigm based on formal logic. A logic program is a set of sentences in logical form, representing knowledge about some problem domain. Computation is performed by applying logical reasoning to that knowledge, to solve problems in the domain. Major logic programming language families include Prolog, Answer Set Programming (ASP) and Datalog. In all of these languages, rules are written in the form of clauses:

Mercury is a functional logic programming language made for real-world uses. The first version was developed at the University of Melbourne, Computer Science department, by Fergus Henderson, Thomas Conway, and Zoltan Somogyi, under Somogyi's supervision, and released on April 8, 1995.

Prolog is a logic programming language that has its origins in artificial intelligence, automated theorem proving and computational linguistics.

In computer science, declarative programming is a programming paradigm—a style of building the structure and elements of computer programs—that expresses the logic of a computation without describing its control flow.

Programming languages can be grouped by the number and types of paradigms supported.

In computer science, reification is the process by which an abstract idea about a program is turned into an explicit data model or other object created in a programming language. A computable/addressable object—a resource—is created in a system as a proxy for a non computable/addressable object. By means of reification, something that was previously implicit, unexpressed, and possibly inexpressible is explicitly formulated and made available to conceptual manipulation. Informally, reification is often referred to as "making something a first-class citizen" within the scope of a particular system. Some aspect of a system can be reified at language design time, which is related to reflection in programming languages. It can be applied as a stepwise refinement at system design time. Reification is one of the most frequently used techniques of conceptual analysis and knowledge representation.

In logic, a logical framework provides a means to define a logic as a signature in a higher-order type theory in such a way that provability of a formula in the original logic reduces to a type inhabitation problem in the framework type theory. This approach has been used successfully for (interactive) automated theorem proving. The first logical framework was Automath; however, the name of the idea comes from the more widely known Edinburgh Logical Framework, LF. Several more recent proof tools like Isabelle are based on this idea. Unlike a direct embedding, the logical framework approach allows many logics to be embedded in the same type system.

SWI-Prolog is a free implementation of the programming language Prolog, commonly used for teaching and semantic web applications. It has a rich set of features, libraries for constraint logic programming, multithreading, unit testing, GUI, interfacing to Java, ODBC and others, literate programming, a web server, SGML, RDF, RDFS, developer tools, and extensive documentation.

<span class="mw-page-title-main">Visual Prolog</span>

Visual Prolog, previously known as PDC Prolog and Turbo Prolog, is a strongly typed object-oriented extension of Prolog. It was marketed by Borland as Turbo Prolog. It is now developed and marketed by the Danish firm PDC that originally created it. Visual Prolog can build Microsoft Windows GUI-applications, console applications, DLLs, and CGI-programs. It can also link to COM components and to databases by means of ODBC.

ECLiPSe is a software system for the development and deployment of constraint logic programming applications, e.g., in the areas of optimization, planning, scheduling, resource allocation, timetabling, transport, etc. It is also suited for teaching most aspects of combinatorial problem solving, e.g., problem modeling, constraint programming, mathematical programming, and search techniques. It contains constraint solver libraries, a high-level modeling and control language, interfaces to third-party solvers, an integrated development environment and interfaces for embedding into host environments.

In computer science, higher-order abstract syntax is a technique for the representation of abstract syntax trees for languages with variable binders.

<span class="mw-page-title-main">Programming language theory</span> Branch of computer science

Programming language theory (PLT) is a branch of computer science that deals with the design, implementation, analysis, characterization, and classification of formal languages known as programming languages. Programming language theory is closely related to other fields including mathematics, software engineering, and linguistics. There are a number of academic conferences and journals in the area.

In computer programming, append is the operation for concatenating linked lists or arrays in some high-level programming languages.

λProlog, also written lambda Prolog, is a logic programming language featuring polymorphic typing, modular programming, and higher-order programming. These extensions to Prolog are derived from the higher-order hereditary Harrop formulas used to justify the foundations of λProlog. Higher-order quantification, simply typed λ-terms, and higher-order unification gives λProlog the basic supports needed to capture the λ-tree syntax approach to higher-order abstract syntax, an approach to representing syntax that maps object-level bindings to programming language bindings. Programmers in λProlog need not deal with bound variable names: instead various declarative devices are available to deal with binder scopes and their instantiations.

Prolog++ is an object-oriented toolkit for the Prolog logic programming language. It allows classes and class hierarchies to be created within Prolog programs.

B-Prolog was a high-performance implementation of the standard Prolog language with several extended features including matching clauses, action rules for event handling, finite-domain constraint solving, arrays and hash tables, declarative loops, and tabling. First released in 1994, B-Prolog is now a widely used CLP system. The constraint solver of B-Prolog was ranked top in two categories in the Second International Solvers Competition, and it also took the second place in P class in the second ASP solver competition and the second place overall in the third ASP solver competition. B-Prolog underpins the PRISM system, a logic-based probabilistic reasoning and learning system. B-Prolog is a commercial product, but it can be used for learning and non-profit research purposes free of charge. B-Prolog is not anymore actively developed, but it forms the basis for the Picat programming language.

The following Comparison of Prolog implementations provides a reference for the relative feature sets and performance of different implementations of the Prolog computer programming language. A comprehensive discussion of the most significant Prolog systems is presented in an article published in the 50-years of Prolog anniversary issue of the journal Theory and Practice of Logic Programming (TPLP).

<span class="mw-page-title-main">Ciao (programming language)</span>

Ciao is a general-purpose programming language which supports logic, constraint, functional, higher-order, and object-oriented programming styles. Its main design objectives are high expressive power, extensibility, safety, reliability, and efficient execution.

Flix is a functional, imperative, and logic programming language developed at Aarhus University, with funding from the Independent Research Fund Denmark, and by a community of open source contributors. The Flix language supports algebraic data types, pattern matching, parametric polymorphism, currying, higher-order functions, extensible records, channel and process-based concurrency, and tail call elimination. Two notable features of Flix are its type and effect system and its support for first-class Datalog constraints.

Dale Miller is an American computer scientist and author. He is a Director of Research at Inria Saclay and one of the designers of the λProlog programming language and the Abella interactive theorem prover.

References

  1. 1 2 3 4 Paulo Moura (2003). Logtalk: Design of an Object-Oriented Logic Programming Language. PhD thesis. Universidade da Beira Interior
  2. Moura, Paulo (2011). Programming Patterns for Logtalk Parametric Objects. Applications of Declarative Programming and Knowledge Management. Lecture Notes in Computer Science. Vol. 6547. doi:10.1007/978-3-642-20589-7_4. ISBN   978-3-642-20588-0.
  3. Practical Aspects of Declarative Languages. Lecture Notes in Computer Science. Vol. 4902. 2008. doi:10.1007/978-3-540-77442-6. ISBN   978-3-540-77441-9.
  4. "Logtalk compatibility". Logtalk.org. 2016-10-10. Retrieved 2021-07-06.
  5. "Developer Tools – LogtalkDotOrg/logtalk3 Wiki – GitHub". Github.com. 2013-02-12. Retrieved 2013-08-19.
  6. Logic Programming. Lecture Notes in Computer Science. Vol. 4079. 2006. doi:10.1007/11799573. ISBN   978-3-540-36635-5.
  7. Victor Noël; Antonis Kakas (2009). Gorgias-C: Extending Argumentation with Constraint Solving (PDF). Logic Programming and Nonmonotonic Reasoning. Lecture Notes in Computer Science. Vol. 5753. pp. 535–541.