Logtalk
Logtalk est un langage de programmation logique, orienté objet, sur-ensemble de Prolog.
Logtalk | |
Date de première version | |
---|---|
Paradigmes | Programmation logique |
Auteur | Paulo Moura |
Dernière version | 3.53.0 () |
Influencé par | Prolog, Smalltalk, Objective-C ; programmation logique, programmation orientée objet, programmation orientée prototype |
Écrit en | Prolog |
Système d'exploitation | Multiplate-forme |
Licence | Apache License 2.0 |
Site web | https://logtalk.org |
Le langage supporte une large gamme de concepts objets :
- la programmation orientée prototype[1],
- les classes[1],
- les interfaces[2],
- l'héritage multiple[3],
- la réflexion[4],
- la réutilisation de code via le concept de catégorie[5],
- le hot-patching[6].
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]:
- B-Prolog 8.1 ou supérieur
- Ciao Prolog 1.20.0 ou supérieur (experimental)
- CxProlog 0.98.1 ou supérieur
- ECLiPSe 6.1#143 ou supérieur
- GNU Prolog 1.4.5 ou supérieur
- JIProlog 4.1.7.1 ou supérieur
- LVM 3.0.0 ou supérieur
- Quintus Prolog 3.3~3.5 (experimental)
- Scryer Prolog 0.8.128 ou supérieur (experimental)
- SICStus Prolog 4.1.0 ou supérieur
- SWI Prolog 6.6.0 ou supérieur
- Tau Prolog 0.3.1 ou supérieur
- Trealla Prolog 1.20.12 ou supérieur (experimental)
- XSB 3.8.0 ou supérieur
- YAP 6.3.4 ou supérieur
Exemple
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This file is part of Logtalk <https://logtalk.org/>
% Copyright 1998-2021 Paulo Moura <pmoura@logtalk.org>
% 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
- « Objects — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Protocols — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Inheritance — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Reflection — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Categories — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Categories — The Logtalk Handbook v3.53.0 documentation », sur logtalk.org (consulté le )
- « Download - Logtalk », sur logtalk.org (consulté le )
- Portail de la programmation informatique
Cet article est issu de Wikipedia. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.