Logtalk

Logtalk
Date de première version Voir et modifier les données sur Wikidata
Paradigmes Programmation logique
Auteur Paulo Moura
Dernière version 3.90.0 (25 mars 2025)
Influencé par Prolog, Smalltalk, Objective-C ; programmation logique, programmation orientée objet, programmation orientée prototype
Écrit en PrologVoir et modifier les données sur Wikidata
Système d'exploitation Multiplate-forme
Licence Apache License 2.0
Site web https://logtalk.org

Logtalk est un langage de programmation logique, orienté objet, sur-ensemble de Prolog.

Le langage supporte une large gamme de concepts objets :

Son implémentation consiste à étendre un système moderne et standard de Prolog via un script adaptateur. Par ce moyen, il supporte à ce jour [7]:

Exemple

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  This file is part of Logtalk <https://logtalk.org/>
%  Copyright 1998-2021 Paulo Moura <[email protected]>
%  SPDX-License-Identifier: Apache-2.0
%
%  Licensed under the Apache License, Version 2.0 (the "License");
%  you may not use this file except in compliance with the License.
%  You may obtain a copy of the License at
%
%      http://www.apache.org/licenses/LICENSE-2.0
%
%  Unless required by applicable law or agreed to in writing, software
%  distributed under the License is distributed on an "AS IS" BASIS,
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%  See the License for the specific language governing permissions and
%  limitations under the License.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% a protocol contains a functionality cohesive set of predicate declarations
% and can be implemented by any number of objects and categories; in this
% example, we start by defining a protocol declaring predicates for common
% physical properties:

:- protocol(physical_properties).

	:- public([
		mass/1, volume/1
	]).

:- end_protocol.


% next, we define two objects, m1 and m2, implementing the protocol:

:- object(m1,
	implements(physical_properties)).

	mass(3).
	volume(2.17).

:- end_object.


:- object(m2,
	implements(physical_properties)).

	mass(4).
	volume(9.21).

:- end_object.


% a category is a fine grained unit of code reuse, used to encapsulate a
% cohesive set of predicate declarations and definitions, implementing a
% single functionality, that can be imported into any object

% categories can be interpreted as the dual concept of protocols, with
% both aiming for functional cohesion with the difference being that
% categories can both declare and define predicates

% in this example, we define a category for declaring planetary properties
% and declaring and defining planetary computations; we don't want to use
% an object as the gravitational_acceleration/1 predicate can only be defined
% for a concrete planet

:- category(planet).

	:- public([
		gravitational_acceleration/1,
		weight/2
	]).

	weight(Object, Weight) :-
		Object::mass(Mass),
		::gravitational_acceleration(Acceleration),
		Weight is Mass * Acceleration.

:- end_category.


% this category can be imported by any number of objects representing actual
% planets, for example, Earth and Mars:

:- object(earth,
	imports(planet)).

	gravitational_acceleration(9.80665).

:- end_object.


:- object(mars,
	imports(planet)).

	gravitational_acceleration(3.72076).

:- end_object.

Notes et références

  1. a et b « Objects — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  2. « Protocols — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  3. « Inheritance — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  4. « Reflection — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  5. « Categories — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  6. « Categories — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
  7. « Download - Logtalk », sur logtalk.org (consulté le )

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.