Include Paulo Moura's Logtalk OO LP system

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@53 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-06-06 19:40:57 +00:00
parent 38247e38fc
commit cc4531cd1e
344 changed files with 27125 additions and 0 deletions

134
Logtalk/LICENSE Normal file
View File

@ -0,0 +1,134 @@
The "Artistic License"
Preamble
The intent of this document is to state the conditions under which a
Package may be copied, such that the Copyright Holder maintains some
semblance of artistic control over the development of the package, while
giving the users of the package the right to use and distribute the
Package in a more-or-less customary fashion, plus the right to make
reasonable modifications.
Definitions
"Package" refers to the collection of files distributed by the
Copyright Holder, and derivatives of that collection of files
created through textual modification.
"Standard Version" refers to such a Package if it has not been
modified, or has been modified in accordance with the wishes of
the Copyright Holder as specified below.
"Copyright Holder" is whoever is named in the copyright or
copyrights for the package.
"You" is you, if you're thinking about copying or distributing
this Package.
"Reasonable copying fee" is whatever you can justify on the basis
of media cost, duplication charges, time of people involved, and
so on. (You will not be required to justify it to the Copyright
Holder, but only to the computing community at large as a market
that must bear the fee.)
"Freely Available" means that no fee is charged for the item
itself, though there may be fees involved in handling the item.
It also means that recipients of the item may redistribute it
under the same conditions they received it.
1. You may make and give away verbatim copies of the source form of the
Standard Version of this Package without restriction, provided that you
duplicate all of the original copyright notices and associated
disclaimers.
2. You may apply bug fixes, portability fixes and other modifications
derived from the Public Domain or from the Copyright Holder. A Package
modified in such a way shall still be considered the Standard Version.
3. You may otherwise modify your copy of this Package in any way,
provided that you insert a prominent notice in each changed file stating
how and when you changed that file, and provided that you do at least
ONE of the following:
a.place your modifications in the Public Domain or otherwise make
them Freely Available, such as by posting said modifications to
Usenet or an equivalent medium, or placing the modifications on a
major archive site such as uunet.uu.net, or by allowing the
Copyright Holder to include your modifications in the Standard
Version of the Package.
b.use the modified Package only within your corporation or
organization.
c.rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and provide
a separate manual page for each non-standard executable that clearly
documents how it differs from the Standard Version.
d.make other distribution arrangements with the Copyright Holder.
4. You may distribute the programs of this Package in object code or
executable form, provided that you do at least ONE of the following:
a.distribute a Standard Version of the executables and library
files, together with instructions (in the manual page or equivalent)
on where to get the Standard Version.
b.accompany the distribution with the machine-readable source of
the Package with your modifications.
c.give non-standard executables non-standard names, and clearly
document the differences in manual pages (or equivalent), together
with instructions on where to get the Standard Version.
d.make other distribution arrangements with the Copyright Holder.
5. You may charge a reasonable copying fee for any distribution of this
Package. You may charge any fee you choose for support of this Package.
You may not charge a fee for this Package itself. However, you may
distribute this Package in aggregate with other (possibly commercial)
programs as part of a larger (possibly commercial) software distribution
provided that you do not advertise this Package as a product of your
own. You may embed this Package's interpreter within an executable of
yours (by linking); this shall be construed as a mere form of
aggregation, provided that the complete Standard Version of the
interpreter is so embedded.
6. The scripts and library files supplied as input to or produced as
output from the programs of this Package do not automatically fall under
the copyright of this Package, but belong to whomever generated them,
and may be sold commercially, and may be aggregated with this Package.
If such scripts or library files are aggregated with this Package via
the so-called "undump" or "unexec" methods of producing a binary
executable image, then distribution of such an image shall neither be
construed as a distribution of this Package nor shall it fall under the
restrictions of Paragraphs 3 and 4, provided that you do not represent
such an executable image as a Standard Version of this Package.
7. C subroutines (or comparably compiled subroutines in other languages)
supplied by you and linked into this Package in order to emulate
subroutines and variables of the language defined by this Package shall
not be considered part of this Package, but are the equivalent of input
as in Paragraph 6, provided these subroutines do not change the language
in any way that would cause it to fail the regression tests for the
language.
8. Aggregation of this Package with a commercial distribution is always
permitted provided that the use of this Package is embedded; that is,
when no overt attempt is made to make this Package's interfaces visible
to the end user of the commercial distribution. Such use shall not be
construed as a distribution of this Package.
9.The name of the Copyright Holder may not be used to endorse or promote
products derived from this software without specific prior written
permission.
10.THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
The End

61
Logtalk/QUICK_START Normal file
View File

@ -0,0 +1,61 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
Quick start
===========
1. Open the manuals/index.html file with a web browser.
2. Select the Tutorial link. This will provide you with a basic understanding
of the main Logtalk concepts.
3. Go back to the index.html file and select the User Manual link and then
the Installing and running Logtalk link. This will provide you with a basic
understanding of how to start Logtalk and compile and load Logtalk code.
Assuming that Logtalk supports your Prolog compiler:
1. Read the NOTES file in the configs sub-directory to check if any patch
or workaround is needed for your compiler.
2. Start your Prolog compiler.
3. Compile and load the config file for your Prolog compiler.
4. Compile and load the Logtalk pre-processor/runtime found in the compiler
sub-directory.
Note that both the configuration files and the compiler/pre-processor
files are Prolog files. The predicate called to load these files depends
on your Prolog compiler. In case of doubt, consult your Prolog compiler
reference manual or take a look at the definition of the predicate
lgt_load_prolog_code/1 in the configuration file.
Now you can try some of the included examples:
1. Open the examples sub-directory. There you find several sub-directories
with ready to run examples. Select and open one of them.
3. Read the example NOTES file. Some examples are dependent on other
examples or on library objects. You may need to load additional files before
running the chosen example.
4. Change the working directory of your Prolog compiler to the example
directory. If you don't know what predicate to use, check the configs/NOTES
file or your Prolog reference manual.
5. Compile and load the file named <example name>.loader. This will compile
and load all the example files. Note that the loader file is a Prolog file.
6. Open the example SCRIPT file. One by one, copy&paste or drag&drop the
queries in the file to your Prolog top-level.
7. Enjoy!

122
Logtalk/README Normal file
View File

@ -0,0 +1,122 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
CONTENTS
1. License
2. Home of Logtalk package
3. Registration
4. Support
5. Installation
6. Documentation
7. Upgrading
8. Contributions
1. LICENSE
The overall copyright and permission notice for Logtalk can be found in
the LICENSE file in this directory. Logtalk follows the Perl Artistic
license. The copyright notice and license applies to all files in this
release (sources, documentation and examples) unless otherwise explicitly
stated.
2. HOME OF LOGTALK PACKAGE
The latest release of the Logtalk package is always available at the
URL:
http://www.ci.uc.pt/logtalk/logtalk.html
At this address you can also find useful documentation and information
about Logtalk.
3. REGISTRATION
To register as a Logtalk user either use the registration form found at
the Logtalk web site or send an email message to:
pmoura@noe.ubi.pt
with the following information:
email address, full name, organization, organization type
(education, commercial, government,...) prolog compilers used (optional),
platforms (mac, pc, unix,...) (optional)
4. SUPPORT
Logtalk support is available for registered users via email to
pmoura@noe.ubi.pt.
At the URL http://www.ci.uc.pt/logtalk/bugs.html you can find a list of
known problems and download bug fixes. The latest news about Logtalk are
available at the URL http://www.ci.uc.pt/logtalk/news.html
There is also a mailing list, logtalk, used to announce new releases and
bug fixes and for discussion between Logtalk users, that you can subscribe.
For instructions on how to subscribe send an email message to:
majordomo@ci.uc.pt
with the words:
help
end
in the body of the message (not in the subject).
5. INSTALLATION
Installing Logtalk is just a matter of uncompressing/unpacking the
distribution archive file for your operating system. You can install
Logtalk in any directory that you find convenient.
See the user manual for a description of the source files organization
and for installing/using instructions (to read the user manual open the
file manuals/index.html with a web browser).
6. DOCUMENTATION
The reference and user manuals and the tutorial are provided in HTML format
and are contained in the manuals directory.
PDF versions of all documentation are also available as a separated download
from the Logtalk web site. The PDF files include page numbers, index and a
table of contents and are available for printing in both A4 and US Letter
paper formats.
The file RELEASE_NOTES contains descriptions of the changes made in
Logtalk since the first public version. Read it carefully if you have
been using a previous Logtalk version.
The file QUICK_START provides quick instructions for those of you in a hurry
to run Logtalk, provided that your usual Prolog compiler is supported.
7. UPGRADING
If you have been using a previous Logtalk version read the file UPGRADING for
instructions on how to upgrade your programs to run under this new version.
8. CONTRIBUTIONS
Contributions, constructive criticisms, code and suggestions are always
welcome. If you want to contribute to this project, drop me a line to the
support address given above.
Happy Logtalking!
Paulo Moura

21
Logtalk/README.YAP Normal file
View File

@ -0,0 +1,21 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
This version of Logtalk included in the YAP distribuition does not
contain configuration files for other Prolog compilers. Also, the
Logtalk compiler/pre-processor is contained in the library/logtalk
directory.
Logtalk can be loaded from YAP either as described in the included
Logtalk documentation or by using the call:
| ?- use_module(library(logtalk)).
Note that, although we load Logtalk using the @code{use_module/1}
built-in predicate, the system is not packaged as a module not does
it use modules in its implementation.

522
Logtalk/RELEASE_NOTES Normal file
View File

@ -0,0 +1,522 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
RELEASE NOTES
=============
2.8.4 - March 9, 2001
Updated config files for BinProlog 8.0, K-Prolog 5.01, XSB 2.3, and
Amzi! Prolog 4.103~5.0.
New config file for Amzi! Prolog 6.1 beta.
Corrected an incomplete entity definition in the Logtalk XML DTD.
Rewrite the Logtalk XSLT files for improved compatibility with XSLT
processors regarding handling of whitespace.
A first cut of a XML Schema for the Logtalk XML documentation files
(file xml/logtalk.xsd).
Small improvements to the documentation.
2.8.3 - November 21, 2000
Corrected a bug where sending a message for a built-in method to an
unknown object fails instead of generating the expected exception.
Put some ocorrences of atoms public, mode, and type between ()'s to
avoid compilation errors in BinProlog 8.0 and other Prolog compilers
that declare these atoms as operators.
Corrected the definition of the state space of the "Missionaires and
Cannibals" problem in the "searching" example that resulted in some
wrong solutions.
2.8.2 - November 5, 2000
New .xsl file to convert .xml files to TeXML files.
Fixed a problem with explicit compilation options being correctly parsed
but not processed.
Corrected a bug regarding default init options definition for the
points, polygons, and bricks examples. Updated category initialization
in roots example.
2.8.1 - October 28, 2000
New config file for K-Prolog 5.0.
Improved compiler error detection and reporting of invalid directives
and clauses.
Corrected a problem with some Prolog compilers where compiling a file
containing syntax errors may not close the file after the errors are
reported.
Many small improvements to all documentation.
Small improvements to the .xsl files and to the output of .xml files.
2.8.0 - October 1, 2000
I have found just a few days ago that I have uploaded to the Logtalk web
server a development version of Logtalk 2.7.0 instead of the final one!
To avoid confusions I decided to release a new version.
Changed implementation of the logtalk_compile/1-2 and logtalk_load/1-2
predicates to only accept a list of entities instead of either an entity
or a list of entities, simplifying and improving the performance of these
predicates. Improved error reporting for the logtalk_compile/1 and
logtalk_load/1 predicates. Updated relevant sessions in the user and
reference manuals.
Simplified the implementation of the following predicates, by sharing
the error checking code with the corresponding extended versions:
implements_protocol/2, imports_category/2, instantiates_class/2,
specializes_class/2, extends_protocol/2, and extends_object/2.
Completed some missing library file dependencies documentation in some
examples.
New version of the QUICK_START help file. Updated tutorial.
2.7.0 - August 24, 2000
First release of the Logtalk standard library of objects, protocols and
categories.
Rewritten all examples to use the new Logtalk standard library.
New logtalk_load/2 and logtalk_compile/2 Logtalk built-in predicates,
accepting a list of compiler options. See the User and Reference Manuals
for details.
New XSLT file for viewing .xml files in Microsoft Internet Explorer 5.5
for Windows after installing the latest Microsoft XML Parser Preview
Release. Small improvements in all XSLT files.
Starting with this version all config files need to provide a definition
for the compare/3 predicate if it is not built-in in the corresponding
Prolog compiler. Also, default Logtalk compiler options are now also set
in the config files using the lgt_default_compiler_option/2 predicate.
Updated config file for CIAO 1.6p1. See the configs/NOTES file for
details.
2.6.2 - July 4, 2000
Improved performance and error checking for the built-in predicates
create_object/4, create_protocol/3 and create_category/4.
Updated config file for BinProlog 7.83.
Many small updates to all documentation.
New PDF versions of the documentation formated for printing (with page
numbers, table of contents and index)are now available in both A4 and
US letter formats.
2.6.1 - May 5, 2000
Modified the structure of the automatically generated XML documenting
files to improve XSL translation performance. Added a new, more standard
compliant, XSL file to generate HTML files and renamed the old one to
ie5.xsl. See the xml/NOTES file for details. Corrected an error in the
logtalk.css CSS file.
Modified the definitions of predicates lgt_file_extension/2 and
lgt_file_name/2 in all config files.
Updated all the user manual sessions related to automatic documentation.
Updated all HTML documentation for future XHTML 1.0 conformance.
Start adding documenting directives to most examples.
2.6.0 - April 27, 2000
Added support for documentation of objects, protocols, and categories,
using automatic generation of XML files.
Added info/1 and info/2 directives for documenting objects, protocols,
categories, and predicates. Added definition of documentation file name
extension and default file names for the DTD and XSL files to the config
files.
Improved error checking for the built-in predicates create_object/4,
create_protocol/3 and create_category/4 to also detect invalid entity
identifiers.
Updated the user and reference manuals to describe the new automatic
documenting features.
Updated all HTML documentation to conform to HTML 4.01 strict standard.
Corrected some wrong cross-reference links and titles in the reference
and user manuals HTML pages.
PDF versions of the manuals and tutorial are now available in both A4
and US letter formats.
Corrected two errors in the searching example, one in the definition of
the farmer problem state space and the other when backtracking over
performance reports.
2.5.2 - March 7, 2000
Updated manuals to clarify some limitations of declaring and defining
dynamic predicates inside categories and documented a way of using the
built-in local method this/1 to access object parameters.
Removed references to parametric categories from the Logtalk
documentation (at runtime we can only access object parameters,
not category parameters).
Corrected two wrong declarations of built-in methods (forall/2 and
retractall/1) in the Logtalk pre-processor.
Corrected bug where predicates declared in dynamic entities may have
a "static" instead of a "dynamic" property.
Corrected a bug in category compilation that prevented a dynamic category
from being abolished. Speedup predicate definition lookups for categories.
2.5.1 - February 18, 2000
Two new examples: birds, a bird identification expert system adopted
(with permission) from an Amzi example, and viewpoints, a set of
prototypes showing how to do property sharing and value sharing in
Logtalk.
Renamed config file yap421.config to yap430.config to match the name of
the new YAP 4.3.0 public release (named 4.2.1 while on beta testing).
Partial config file for Trinc Prolog R3.
2.5.0 - December 29, 1999
The Logtalk pre-processor now accepts arbitrary clauses and directives
to appear in a file before an opening entity directive. The clauses and
directives are added unchanged to the compiled file.
Improved performance for all kinds of message sending.
Two new examples: reflection, showing how to implement a simple
class-based reflective system, and symdiff, showing how to use
parametric objects to implement symbolic expression differentiation
and simplification.
Updated config file for the beta 8 release of SWI-Prolog 3.3.0.
2.4.0 - December 1, 1999
Logtalk is now an Open Source project, available under Perl's Artistic
license.
Two new examples: instmethods, ilustrating the use of instance defined
methods, and classvars, showing how to implement class variables.
Updated Logtalk grammar to explicitly allow for user-defined types
in mode/2 directives.
New config files for SWI-Prolog 3.3.0, SICStus Prolog 3.8 and CIAO
Prolog 1.4p0 (incomplete).
Updated config file for B-Prolog 4.0.
Updated config file for GNU Prolog to use the new call_with_args()
built-in predicate added in version 1.1.0.
Updated config file for YAP Prolog to use the new call_with_args()
built-in predicate added in version 4.2.1.
2.3.1 - September 22, 1999
Logtalk pre-processor updated to only report one warning per redefined
Logtalk or Prolog built-in predicate.
Changed some occurrences of atom "public" to "(public)" in
compiler/logtalk.pl file to avoid syntax errors in Prolog compilers
(like BinProlog) that define "public" as an operator. Also put some
terms between ()'s to avoid syntax errors with ALS Prolog 3.1
Update config file for ALS Prolog to work with version 3.1.
Updated configs/NOTES file include a workaround to use Logtalk with
XSB 2.0, some guidelines on how to write loader utility files for
BinProlog 7.50, and a bug in ALS Prolog 3.1 that affects Logtalk.
2.3.0 - September 12, 1999
Metapredicate information is now stored with the other predicate
properties, instead of being discarded after compiling the clauses of
a metapredicate. Added predicate property metapredicate/1. It is now
possible to assert clauses for dynamic metapredicates.
Corrected a bug in the processing of metacalls in pseudo-object user.
Corrected a bug in the implementation of private inheritance.
Improved performance of protected inheritance.
Corrected failure of processing initialization/1 and op/3 directives in
create_object/4, create_category/4 and create_protocol/3 built-in
predicates.
Corrected a bug when calling private static category predicates from
importing objects. Simplified code generated for categories.
Rewrite code for the built-in method current_predicate/1 to avoid
duplicated or wrong results when overriding predicate declarations
and to ensure that all possible argument type errors are detected.
Changed compilation of classes that do not instantiate any (meta)class
in order to throw the correct exception when a message is sent to them.
Changed compilation of root objects (that do not instantiate, specialize
or extend other objects) so that calls to "super" (^^/1) fail (as they
should) instead of generating a "predicate does not exist" error message.
Changed implementation of "super" calls (^^/1) to avoid a potential
endless loop problem when using these calls from the inheritance root
object of a reflexive class-based systems.
Pre-processor now checks for callable and object identifier errors.
Runtime now checks for non-instantiated messages.
Added new example (inheritance) about public, protected and private
inheritance.
Updated metapredicates, lo, kernel, and types examples. Most of the
code in the last two examples is being updated to form the basis of an
upcoming Logtalk standard library.
Small changes in the pre-processor/runtime code for compatibility with
ECLiPSe 4.2.2. Updated config files for this Prolog compiler.
Rewrite some predicates in the config files for SWI-Prolog and LPA
Mac & WIN Prologs for improved performance.
New tutorial session about events and monitors.
Updated documentation to match the changes made in this version.
2.2.0 - July 10, 1999
Implemented public, protected and private object inheritance, protocol
implementation and category importation.
New Logtalk built-in predicates instantiates_class/3, extends_object/3,
extends_protocol/3, specializes_class/3, imports_category/3 and
implements_protocol/3. The third argument returns the relation scope.
Pre-processor now checks most directive errors.
Changed ^^/1 (super call) implementation to only allow the use of a
single predicate call for argument and to retain the original sender
of the message (see the updated sicstus example).
Fixed bug that prevented directives with a variable number of arguments
(like dynamic(), public(), uses(), ...) being recognized.
Changed definition of predicate read_term/3 in the configs files of Amzi!,
Aquarius, Arity, Eclipse, IC, K, LPA Mac&WIN, Master and XSB to always
instantiates the singleton variables list to the empty list. Needed to
prevent backtracking problems in logtalk_load/1 and logtalk_compile/1
predicates.
Removed choice-point in processing metacalls in predicate definitions.
A banner with the Logtalk version is printed after loading the runtime/
pre-processor.
Removed variables example. The category attributes is now part of the
kernel example. Corrected some warmless syntax errors in directives in
kernel/attributes.lgt, kernel/monitor.lgt and miscellaneous/queens.lgt.
Changed name of blocks example to bricks and object "block" to "brick"
in order to avoid problems with some Prolog compilers that use the atom
"block" for operators or built-in predicates.
2.1.0 - May 11, 1999
Fixed some bugs in the definition of the pseudo-object user when sending
the message predicate_property/2.
Renamed config file for Calypso to GNU Prolog.
New config file for LPA WinProlog 4.0.
Corrected the omission in the documentation of the Logtalk grammar of the
built_in entity property.
New tutorial pages about building reflective class-based systems.
Modified pre-processor to compile throw/1 as a control structure to
ensure compatibility with the GNU-Prolog compiler.
Modified pre-processor to ensure compatibility with Prolog compilers that
use immediate update semantics instead of the ISO logical database update.
Improved simplification of compiled object and category clauses.
Rewrite and clean up pre-processor code for better compiler performance.
Several updates to the examples files.
Changed all example loader files to wrap the call to logtalk_load/1 inside
an initialization/1 directive for ISO standard compliance.
2.0 GM - February 9, 1999
Removed some redundant choice-points that are being created when
compiling Logtalk entities.
Small compilation speed optimizations.
Logtalk compiled files now contain the declarations for the message
sending operators to ensure compatibility with some Prolog compilers.
Changed the way Logtalk pre-processor writes directives to ensure
compatibility with some Prolog compilers. Corrected a bug in the
processing of the op/3 directive.
Updated PrologII+ config file for version 4.5.
Changed the definitions of catch/3 and throw/1 in the config files for
LPA Prolog compilers.
New config file for MasterProlog 4.1; removed config file for the
old BIM Prolog 4.0.
Corrected an error in the config file for OpenProlog in the definiton
of the write_term/3 predicate.
Added a safer definition for write_term/3 predicate in the config
files for Amzi, Aquarius, Arity, Eclipse, IC, K, LPA Mac, LPA Win,
and XSB Prolog compilers.
Added a QUICK_START file.
2.0 Beta 3 - February 1, 1999
Closed some encapsulation holes in the implementation of super calls.
Changed Logtalk pre-processor to use write_term/3 instead of write/2 and
writeq/2 to workaround some compatibility problems with some Prolog
compilers.
Changed mode operators priority and type to be compatible with the ISO
standard.
Modified definition of predicate read_term/3 in the config file for Amzi
compiler to return the atom end_of_file instead of '!EOF' at the end of
a file (this prevented Logtalk to complete compilation any file under
this compiler). Improved detection of built-in predicates while compiling.
Removed config file for wamcc. This compiler have been replaced by
Calypso (developed by the same author).
Updated K-Prolog config file for version 4.50.
Improved documentation of template config file.
Added SCRIPT files to the kernel and types examples.
Updated Tutorial and User and Reference Manuals.
New end user license.
2.0 Beta 2 - November 16, 1998
Built-ins logtalk_compile/1 and logtalk_load/1 updated to match
the documentation regarding thrown errors and to accept a list of
entities to compile/load.
Modified the examples loader utility files to make only a call to
logtalk_load/1 by using a list of entities. This should make it easy to
modify these files for compilers that don't support arbritrary queries
in a file.
Logtalk runtime no longer tries to catch some of the errors thrown
by ::/2.
Added to all config files a Logtalk predicate to check if a file
exists in the current working directory (used by the logtalk_load/1
and logtalk_compile/1 Logtalk built-in predicates).
New configs files for the K-Prolog 4.14 and Calypso 1.0b6 Prolog
compilers.
Completed the config file for Open Prolog 1.03d38 (with the exception
of lgt_current_date/3 that still have a dummy definition).
Added a missing definition for Logtalk predicate forall/2 to the config
file for Prolog II+ 4.4.
Modified Logtalk pre-processor/runtime to avoid syntax errors when
running on Open Prolog or Calypso and to remove some redundant
choice-points that are being created when compiling categories and
protocols.
Modified some examples that use operators to avoid syntax errors in
some Prolog compilers.
Modified the implementation of the built-in method
predicate_property/2 to avoid duplicate answers and to throw an
instantiation error if the first argument is not bound.
Modified definition of the pseudo-object user to hide Logtalk pre-
processor predicates from the current_predicate/1 built-in method and
to ensure that the predicate_property/2 built-in method returns
Logtalk defined predicate properties for built-in Logtalk and Prolog
predicates.
Modified Prolog code generated by the pre-processor to further minimize
possible conflicts with user defined predicates.
Added a lgt_predicate_property/2 predicate to the config files to
improve Logtalk portability.
Updated Tutorial and User and Reference Manuals.
2.0 Beta 1 - October 18, 1998
Added basic support for implementation multi-inheritance.
Logtalk pre-processor updated to try to detect misspelt local
predicate calls.
First public beta.
2.0 Alpha 1 - July, 1998
First release for registered users.

36
Logtalk/UPGRADING Normal file
View File

@ -0,0 +1,36 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
Upgrading from Logtalk 1.x
==========================
Logtalk 2.x is not compatible with programs written for version 1.x.
However, you should be able to translate most programs to make them
run under this new version. Most of the examples provided with previous
versions have been rewritten to run under version 2.x. Use them as
translation examples.
Upgrading from a previous Logtalk 2.x version
=============================================
If your Logtalk programs depend on some of the example files, it is
advisable that you check your code against the new version before
throwing away the older release.
Logtalk source files will need to be recompiled because of the changes
done in the version 2.5.0 to improve message sending performance.
Logtalk version 2.7.0 provides the first cut of the Logtalk standard library.
Most examples have been rewritten to take advantage of the library.
Logtalk version 2.8.0 introduces a small change on the logtalk_compile/1-2
and logtalk_load/1-2 predicates that may imply updating your loader utility
files: the first argument is now always a list of entities even if we want
to compile or laod a single entity.

View File

@ -0,0 +1,64 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the birds.loader utility
file.
You will also need to also load the library/hierarchies.loader file.
Note that the *.loader files are Prolog files.
This folder contains an example of a bird identification expert system
adopted with permission from the book "Adventure in Prolog" by Amzi! inc.
The book is available on-line in HTML format at the URL:
http://www.amzi.com
Please refer to the book for more information on the original example.
The bird identification hierarchy is organized as a prototype hierarchy
as follows:
<order>
<family>
<bird>
order
falconiforms
falcon
peregrine_falcon
sparrow_hawk
vulture
california_condor
turkey_vulture
passerformes
flycatcher
ash_throated_flycatcher
great_crested_flycatcher
swallow
barn_swallow
cliff_swallow
purple_martin
tubenose
fulmar
albatross
black_footed_albatross
laysan_albatross
waterfowl
duck
female_mallard
male_mallard
pintail
goose
canada_goose
snow_goose
swan
trumpeter_swan
whistling_swan

View File

@ -0,0 +1,72 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% ask the expert system for help in identifying a bird:
| ?- expert::identify.
Bird identification expert system
bill:sharp_hooked? (yes or no): yes.
eats:birds? (yes or no): yes.
feet:curved_talons? (yes or no): yes.
head:large? (yes or no): yes.
What is the value for tail?
1 : narrow_at_tip
2 : forked
3 : long_rusty
4 : square
5 : other
Enter the number of choice> 1.
wings:long_pointed? (yes or no): yes.
Possible identification : peregrine_falcon
No (more) candidates found.
(16379 ms) yes
% identify another bird:
| ?- expert::identify.
Bird identification expert system
bill:sharp_hooked? (yes or no): no.
bill:flat? (yes or no): no.
bill:short? (yes or no): no.
bill:hooked? (yes or no): yes.
What is the value for flight?
1 : ponderous
2 : powerful
3 : agile
4 : flap_glide
5 : other
Enter the number of choice> 2.
color:dark? (yes or no): yes.
live:at_sea? (yes or no): yes.
nostrils:external_tubular? (yes or no): yes.
What is the value for size?
1 : large
2 : plump
3 : medium
4 : small
Enter the number of choice> 1.
wings:long_narrow? (yes or no): yes.
Possible identification : black_footed_albatross
No (more) candidates found.
(34624 ms) yes
| ?-

View File

@ -0,0 +1,14 @@
:- object(albatross,
imports(descriptors),
extends(tubenose)).
family(albatross).
size(large).
wings(long_narrow).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(ash_throated_flycatcher,
imports(descriptors),
extends(flycatcher)).
throat(white).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(barn_swallow,
imports(descriptors),
extends(swallow)).
tail(forked).
:- end_object.

View File

@ -0,0 +1,41 @@
:- initialization(
logtalk_load([
descriptors,
expert,
order,
falconiforms, % orders
passerformes,
tubenose,
waterfowl,
albatross, % families
duck,
falcon,
flycatcher,
goose,
swallow,
swan,
vulture,
ash_throated_flycatcher, % birds
barn_swallow,
black_footed_albatross,
california_condor,
canada_goose,
cliff_swallow,
female_mallard,
fulmar,
great_crested_flycatcher,
laysan_albatross,
male_mallard,
peregrine_falcon,
pintail,
purple_martin,
snow_goose,
sparrow_hawk,
trumpeter_swan,
turkey_vulture,
whistling_swan])).

View File

@ -0,0 +1,10 @@
:- object(black_footed_albatross,
imports(descriptors),
extends(albatross)).
color(dark).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(california_condor,
imports(descriptors),
extends(vulture)).
flight_profile(flat).
:- end_object.

View File

@ -0,0 +1,12 @@
:- object(canada_goose,
imports(descriptors),
extends(goose)).
head(black).
cheek(white).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(cliff_swallow,
imports(descriptors),
extends(swallow)).
tail(square).
:- end_object.

View File

@ -0,0 +1,56 @@
:- category(descriptors).
:- info([
authors is 'Paulo Moura',
version is 1.0,
date is 2000/2/18,
comment is 'Bird descriptors predicates.',
source is 'Example adopted from an Amzi! Inc Prolog book.']).
:- public([
bill/1,
cheek/1,
color/1,
eats/1,
family/1,
feed/1,
feet/1,
flight/1,
flight_profile/1,
head/1,
live/1,
neck/1,
nostrils/1,
order/1,
size/1,
tail/1,
throat/1,
voice/1,
wings/1]).
:- public(descriptor/1).
descriptor(bill/1).
descriptor(cheek/1).
descriptor(color/1).
descriptor(eats/1).
descriptor(feed/1).
descriptor(feet/1).
descriptor(flight/1).
descriptor(flight_profile/1).
descriptor(head/1).
descriptor(live/1).
descriptor(neck/1).
descriptor(nostrils/1).
descriptor(size/1).
descriptor(tail/1).
descriptor(throat/1).
descriptor(voice/1).
descriptor(wings/1).
:- end_category.

View File

@ -0,0 +1,14 @@
:- object(duck,
imports(descriptors),
extends(waterfowl)).
family(duck).
feed(on_water_surface).
flight(agile).
:- end_object.

View File

@ -0,0 +1,166 @@
:- object(expert,
imports(protected::descriptors)).
:- info([
authors is 'Paulo Moura',
version is 1.0,
date is 2000/2/18,
comment is 'Expert system for bird identification.',
source is 'Example adopted from an Amzi! Inc Prolog book.']).
:- public(identify/0).
:- mode(identify, one).
:- info(identify/0,
[comment is 'Starts a bird identification session.']).
:- private(known_/3).
:- dynamic(known_/3).
:- mode(known_(?nonvar, ?nonvar, ?nonvar), zero_or_more).
:- info(known_/3, [
comment is 'Table of already known facts.',
argnames is ['Answer', 'Attribute', 'Value']]).
identify :-
::retractall(known_(_, _, _)),
write('Bird identification expert system'), nl, nl,
forall(
(order::leaf(Bird), check(Bird)),
(nl, write('Possible identification : '), write(Bird), nl)),
nl, write('No (more) candidates found.').
check(Bird) :-
forall(
(::descriptor(Functor/Arity),
functor(Predicate, Functor, Arity),
Bird::Predicate),
call(Predicate)).
bill(X):-
ask(bill, X).
cheek(X):-
ask(cheek, X).
color(X):-
ask(color, X).
eats(X):-
ask(eats, X).
feed(X):-
ask(feed,X).
feet(X):-
ask(feet, X).
flight(X):-
menuask(flight, X, [ponderous, powerful, agile, flap_glide, other]).
flight_profile(X):-
menuask(flight_profile, X, [flat, v_shaped, other]).
head(X):-
ask(head,X).
live(X) :-
ask(live, X).
neck(X):-
ask(neck, X).
nostrils(X):-
ask(nostrils, X).
size(X):-
menuask(size, X, [large, plump, medium, small]).
tail(X):-
menuask(tail, X, [narrow_at_tip, forked, long_rusty, square, other]).
throat(X):-
ask(throat, X).
voice(X):-
ask(voice,X).
wings(X):-
ask(wings, X).
ask(Attribute,Value):-
::known_(yes, Attribute, Value),
!.
ask(Attribute,Value):-
::known_(_, Attribute, Value),
!, fail.
ask(Attribute,_):-
::known_(yes, Attribute, _),
!, fail.
ask(Attribute, Value):-
write(Attribute:Value),
write('? (yes or no): '),
read(Answer),
::asserta(known_(Answer, Attribute, Value)),
Answer = yes.
menuask(Attribute,Value, _):-
::known_(yes, Attribute, Value),
!.
menuask(Attribute, _, _):-
::known_(yes, Attribute, _),
!, fail.
menuask(Attribute, AskValue, Menu):-
nl, write('What is the value for '), write(Attribute), write('?'), nl,
display_menu(Menu),
write('Enter the number of choice> '),
read(Num),nl,
pick_menu(Num, AnswerValue, Menu),
::asserta(known_(yes,Attribute,AnswerValue)),
AskValue = AnswerValue.
display_menu(Menu):-
display_menu(Menu, 1).
display_menu([], _).
display_menu([Item| Rest], N):-
write(N), write(' : '), write(Item), nl,
NN is N + 1,
display_menu(Rest, NN).
pick_menu(N, Val, Menu):-
integer(N),
pic_menu(1, N, Val, Menu), !.
pick_menu(Val, Val, _).
pic_menu(_, _, none_of_the_above, []).
pic_menu(N, N, Item, [Item| _]).
pic_menu(Ctr, N, Val, [_| Rest]):-
NextCtr is Ctr + 1,
pic_menu(NextCtr, N, Val, Rest).
:- end_object.

View File

@ -0,0 +1,16 @@
:- object(falcon,
imports(descriptors),
extends(falconiforms)).
family(falcon).
wings(long_pointed).
head(large).
tail(narrow_at_tip).
:- end_object.

View File

@ -0,0 +1,16 @@
:- object(falconiforms,
imports(descriptors),
extends(order)).
order(falconiforms).
eats(meat).
feet(curved_talons).
bill(sharp_hooked).
:- end_object.

View File

@ -0,0 +1,12 @@
:- object(female_mallard,
imports(descriptors),
extends(duck)).
voice(quack).
color(mottled_brown).
:- end_object.

View File

@ -0,0 +1,14 @@
:- object(flycatcher,
imports(descriptors),
extends(passerformes)).
family(flycatcher).
bill(flat).
eats(flying_insects).
:- end_object.

View File

@ -0,0 +1,12 @@
:- object(fulmar,
imports(descriptors),
extends(tubenose)).
size(medium).
flight(flap_glide).
:- end_object.

View File

@ -0,0 +1,14 @@
:- object(goose,
imports(descriptors),
extends(waterfowl)).
family(goose).
size(plump).
flight(powerful).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(great_crested_flycatcher,
imports(descriptors),
extends(flycatcher)).
tail(long_rusty).
:- end_object.

View File

@ -0,0 +1,11 @@
:- object(laysan_albatross,
imports(descriptors),
extends(albatross)).
color(white).
:- end_object.

View File

@ -0,0 +1,12 @@
:- object(male_mallard,
imports(descriptors),
extends(duck)).
voice(quack).
head(green).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(order,
imports(descriptors, proto_hierarchy)).
:- end_object.

View File

@ -0,0 +1,12 @@
:- object(passerformes,
imports(descriptors),
extends(order)).
order(passerformes).
feet(one_long_backward_toe).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(peregrine_falcon,
imports(descriptors),
extends(falcon)).
eats(birds).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(pintail,
imports(descriptors),
extends(duck)).
voice(short_whistle).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(purple_martin,
imports(descriptors),
extends(swallow)).
color(dark).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(snow_goose,
imports(descriptors),
extends(goose)).
color(white).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(sparrow_hawk,
imports(descriptors),
extends(falcon)).
eats(insects).
:- end_object.

View File

@ -0,0 +1,16 @@
:- object(swallow,
imports(descriptors),
extends(passerformes)).
family(swallow).
wings(long_pointed).
tail(forked).
bill(short).
:- end_object.

View File

@ -0,0 +1,16 @@
:- object(swan,
imports(descriptors),
extends(waterfowl)).
family(swan).
neck(long).
color(white).
flight(ponderous).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(trumpeter_swan,
imports(descriptors),
extends(swan)).
voice(loud_trumpeting).
:- end_object.

View File

@ -0,0 +1,16 @@
:- object(tubenose,
imports(descriptors),
extends(order)).
order(tubenose).
nostrils(external_tubular).
live(at_sea).
bill(hooked).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(turkey_vulture,
imports(descriptors),
extends(vulture)).
flight_profile(v_shaped).
:- end_object.

View File

@ -0,0 +1,14 @@
:- object(vulture,
imports(descriptors),
extends(falconiforms)).
family(vulture).
feed(scavange).
wings(broad).
:- end_object.

View File

@ -0,0 +1,14 @@
:- object(waterfowl,
imports(descriptors),
extends(order)).
order(waterfowl).
feet(webbed).
bill(flat).
:- end_object.

View File

@ -0,0 +1,10 @@
:- object(whistling_swan,
imports(descriptors),
extends(swan)).
voice(muffled_musical_whistle).
:- end_object.

View File

@ -0,0 +1,26 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the bricks.loader utility
file (note that the *.loader files are Prolog files).
You will need to load the objects in the roots and relations
examples (consulting the corresponding roots.loader and relations.loader
files).
You will also need to consult the following files in the library directory:
events.loader, types.loader, metapredicates.loader, and hierarchies.loader.
This folder contains an example of representation and handling of
relations using events. We have instances of class brick and a binary
brick_stack relation between the bricks. Every time we move a brick, we
want the bricks on top of it to move along. If we break the stack by
moving a middle brick, we want to automatically destroy the
corresponding relation tuple.
It's instructive to use the debugger to better understand this example.
Set spy points in all brick instances and then activate the debugger.

View File

@ -0,0 +1,225 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% create four bricks, all standing on the "ground" (use your imagination... ;-)
| ?- brick::new(a, [position-(8, 1)]).
yes
| ?- brick::new(b, [position-(6, 1)]).
yes
| ?- brick::new(c, [position-(4, 1)]).
yes
| ?- brick::new(d, [position-(2, 1)]).
yes
% set up ascii stack monitor so we can watch the bricks moving
| ?- after_event_registry::set_monitor(_, move(_,_), _, stack_monitor).
yes
% make the stack
| ?- brick_stack::add_tuple([c,d]).
|.c......
|.d...b.a
---------
yes
| ?- brick_stack::add_tuple([b,c]).
|.b......
|.c......
|.d.....a
---------
yes
| ?- brick_stack::add_tuple([a,b]).
|.a
|.b
|.c
|.d
---
yes
% check results
| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
[c,d]
[b,c]
[a,b]
no
| ?- before_event_registry::monitors(Mb), after_event_registry::monitors(Ma).
Ma = [brick_stack, stack_monitor]
Mb = [brick_stack]
yes
% move all stack to new position by moving bottom brick; check results
| ?- d::move(9, 1).
|.a.......
|.b.......
|.c.......
|........d
----------
|.a.......
|.b.......
|........c
|........d
----------
|.a.......
|........b
|........c
|........d
----------
|........a
|........b
|........c
|........d
----------
yes
| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
Xa = 9,
Xb = 9,
Xc = 9,
Xd = 9,
Ya = 4,
Yb = 3,
Yc = 2,
Yd = 1
yes
| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
[c,d]
[b,c]
[a,b]
no
% break stack in half by moving b to the "ground"; check results
| ?- b::move(3, 1).
|........a
|.........
|........c
|..b.....d
----------
|..a.....c
|..b.....d
----------
yes
| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
Xa = 3,
Xb = 3,
Xc = 9,
Xd = 9,
Ya = 2,
Yb = 1,
Yc = 2,
Yd = 1
yes
| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
[c,d]
[a,b]
no
% create new brick_stack tuple ; check results
| ?- brick_stack::add_tuple([d, a]).
|..d......
|..a.....c
|..b......
----------
|..c
|..d
|..a
|..b
----
yes
| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
Xa = 3,
Xb = 3,
Xc = 3,
Xd = 3,
Ya = 2,
Yb = 1,
Yc = 4,
Yd = 3
yes
| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
[c,d]
[a,b]
[d,a]
no
% move all stack to new position by moving bottom brick; check results
| ?- b::move(5, 1).
|..c..
|..d..
|..a..
|....b
------
|..c..
|..d..
|....a
|....b
------
|..c..
|....d
|....a
|....b
------
|....c
|....d
|....a
|....b
------
yes
| ?- a::position(Xa, Ya), b::position(Xb, Yb), c::position(Xc, Yc), d::position(Xd, Yd).
Xa = 5,
Xb = 5,
Xc = 5,
Xd = 5,
Ya = 2,
Yb = 1,
Yc = 4,
Yd = 3
yes
| ?- brick_stack::tuple(Tuple), write(Tuple), nl, fail.
[c,d]
[a,b]
[d,a]
no
% clean up instances, tuples and monitors
| ?- brick_stack::remove_all_tuples.
yes
| ?- after_event_registry::del_monitors(_, _, _, stack_monitor).
yes
| ?- brick::delete_all.
yes

View File

@ -0,0 +1,76 @@
:- object(brick,
instantiates(class),
specializes(object)).
:- info([
version is 1.1,
date is 2000/10/31,
authors is 'Paulo Moura',
comment is 'Two-dimensional brick (or should I say square?) class.']).
:- public(position/2).
:- mode(position(?integer, ?integer), zero_or_one).
:- info(position/2, [
comment is 'Brick current position.',
argnames is ['X', 'Y']]).
:- private(position_/2).
:- dynamic(position_/2).
:- mode(position_(?integer, ?integer), zero_or_one).
:- info(position_/2, [
comment is 'Stores brick current position.',
argnames is ['X', 'Y']]).
:- public(move/2).
:- mode(move(+integer, +integer), one).
:- info(move/2, [
comment is 'Moves a brick to a new position.',
argnames is ['X', 'Y']]).
position(X, Y) :-
::position_(X, Y).
move(X, Y) :-
::retractall(position_(_, _)),
::assertz(position_(X, Y)).
default_init_option(position-(0, 0)).
default_init_option(Default) :-
^^default_init_option(Default).
process_init_option(position-(X, Y)) :-
::assertz(position_(X, Y)).
process_init_option(Option) :-
^^process_init_option(Option).
valid_init_option(position-(X, Y)) :-
!,
integer(X),
integer(Y).
valid_init_option(Option) :-
^^valid_init_option(Option).
instance_base_name(b).
:- end_object.

View File

@ -0,0 +1,59 @@
:- object(brick_stack,
instantiates(constrained_relation)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Stack of bricks as a constrained binary relation.']).
descriptor_([top, bottom]).
domain_(top, brick).
domain_(bottom, brick).
key_([top, bottom]).
cardinality_(top, 0, 1).
cardinality_(bottom, 0, 1).
delete_option_(top, cascade).
delete_option_(bottom, restrict).
add_tuple([A, B]) :-
B::position(Xb, Yb),
Ya2 is Yb + 1,
{A::move(Xb, Ya2)},
^^add_tuple([A, B]).
activ_points_(top, before, []).
activ_points_(top, after, [move(_, _)]).
activ_points_(bottom, before, []).
activ_points_(bottom, after, [move(_, _)]).
propagate(after, move(X, Y), Top, top, [Top, Bottom]) :-
!,
Y2 is Y - 1,
(Bottom::position(X, Y2) ->
true
;
::remove_tuple([Top, Bottom])).
propagate(after, move(X, Y), Bottom, bottom, [Top, Bottom]) :-
!,
Y2 is Y + 1,
{Top::move(X, Y2)}.
:- end_object.

View File

@ -0,0 +1,6 @@
:- initialization(
logtalk_load([
brick,
brick_stack,
stack_monitor])).

View File

@ -0,0 +1,38 @@
:- object(stack_monitor,
implements(event_handlersp)).
:- info([
version is 1.0,
date is 1998/3/23,
authors is 'Paulo Moura',
comment is 'Monitor for brick movements printing an ascii representation of each brick position.']).
:- uses(loop).
:- uses(list).
after(_, move(_, _), _) :-
findall(
(Brick, X, Y),
(instantiates_class(Brick, brick), Brick::position(X, Y)),
Bricks),
setof(X, Brick^Y^ (list::member((Brick,X,Y), Bricks)), Xs),
list::last(Xs, Xmax),
setof(Y, Brick^X^ (list::member((Brick,X,Y), Bricks)), Ys),
list::last(Ys, Ymax),
loop::fordownto(Y, Ymax, 1,
(write('|'),
loop::forto(X, 1, Xmax,
(list::member((Brick, X, Y), Bricks) ->
write(Brick)
;
write('.'))),
nl)),
write('-'),
loop::forto(X, 1, Xmax, write('-')), nl.
:- end_object.

View File

@ -0,0 +1,15 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the classvars.loader utility
file (note that the *.loader files are Prolog files).
This folder contains an example that shows how to implement class variables
as defined in Smalltalk. The name shared instance variables is however much
more accurate. In systems like Logtalk that enable the use of explicit
metaclasses, true class variables are just the class (as an object) own
instance variables!

View File

@ -0,0 +1,32 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% get the value of the class variable for each instance:
| ?- instance1::cv(Value1), instance2::cv(Value2), instance3::cv(Value3).
Value1 = 0
Value2 = 0
Value3 = 0
yes
% change the value of the class variable via instance1:
| ?- instance1::set_cv(1).
yes
% get the value of the class variable for the other instances:
| ?- instance2::cv(Value2), instance3::cv(Value3).
Value2 = 1
Value3 = 1
yes

View File

@ -0,0 +1,7 @@
:- initialization(
logtalk_load([
root,
instance1,
instance2,
instance3])).

View File

@ -0,0 +1,6 @@
:- object(instance1,
instantiates(root)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(instance2,
instantiates(root)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(instance3,
instantiates(root)).
:- end_object.

View File

@ -0,0 +1,29 @@
:- object(root,
instantiates(root)).
:- private(cv_/1).
:- dynamic(cv_/1).
:- mode(cv_(?integer), zero_or_one).
:- public(cv/1).
:- mode(cv(?integer), zero_or_one).
:- public(set_cv/1).
:- mode(set_cv(+integer), one).
cv_(0). % cv value is stored locally, in this class
cv(Value) :-
cv_(Value). % retrive cv value, shared for all instances
set_cv(Value) :-
retractall(cv_(_)), % retract old cv value from this class
asserta(cv_(Value)). % assert the new value in this class
:- end_object.

View File

@ -0,0 +1,16 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the inheritance.loader utility
file (note that the *.loader files are Prolog files).
This folder contains examples of public, protected and private inheritance,
for both prototypes and classes/instances. The category "predicates" defines
a set of three predicates, one public, one protected and one private. This
category is imported by the root objects: "parent" for the prototypes and
"object" for the classes/instances. Each root object have a set of three
descendants, each one using one of the inheritance types.

View File

@ -0,0 +1,98 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% parent interface
| ?- parent::interface.
public/0 - public
protected/0 - protected
private/0 - private
interface/0 - public
yes
% prototype1 extends public::parent
| ?- prototype1::interface.
interface/0 - public
public/0 - public
protected/0 - protected
yes
% prototype2 extends protected::parent
| ?- prototype2::interface.
interface/0 - public
public/0 - protected
protected/0 - protected
yes
% prototype3 extends private::parent
| ?- prototype3::interface.
interface/0 - public
public/0 - private
protected/0 - private
yes
% object (root of the inheritance graph) interface
| ?- root::interface.
public/0 - public
protected/0 - protected
private/0 - private
interface/0 - public
yes
% instance1 instantiates subclass1 that specializes public::root
| ?- instance1::interface.
interface/0 - public
public/0 - public
protected/0 - protected
yes
% instance2 instantiates subclass2 that specializes protected::root
| ?- instance2::interface.
interface/0 - public
public/0 - protected
protected/0 - protected
yes
% instance3 instantiates subclass3 that specializes private::root
| ?- instance3::interface.
interface/0 - public
public/0 - private
protected/0 - private
yes

View File

@ -0,0 +1,18 @@
:- initialization(
logtalk_load([
predicates,
interface,
parent,
prototype1,
prototype2,
prototype3,
root,
subclass1,
subclass2,
subclass3,
instance1,
instance2,
instance3])).

View File

@ -0,0 +1,6 @@
:- object(instance1,
instantiates(subclass1)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(instance2,
instantiates(subclass2)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(instance3,
instantiates(subclass3)).
:- end_object.

View File

@ -0,0 +1,22 @@
:- category(interface).
:- public(interface/0).
:- mode(interface, one).
interface :-
forall(
(::current_predicate(Functor/Arity),
functor(Pred, Functor, Arity)),
(::predicate_property(Pred, Prop), scope(Prop),
writeq(Functor/Arity), write(' - '), writeq(Prop), nl)).
scope(public).
scope(protected).
scope(private).
:- end_category.

View File

@ -0,0 +1,6 @@
:- object(parent,
imports(predicates, interface)).
:- end_object.

View File

@ -0,0 +1,25 @@
:- category(predicates).
:- public(public/0).
:- mode(public, one).
:- protected(protected/0).
:- mode(protected, one).
:- private(private/0).
:- mode(private, one).
public :-
write('Public predicate declared and defined in category predicates.'), nl.
protected :-
write('Protected predicate declared and defined in category predicates.'), nl.
private :-
write('Private predicate declared and defined in category predicates.'), nl.
:- end_category.

View File

@ -0,0 +1,7 @@
:- object(prototype1,
imports(interface),
extends(public::parent)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(prototype2,
imports(interface),
extends(protected::parent)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(prototype3,
imports(interface),
extends(private::parent)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(root,
imports(predicates, interface),
instantiates(root)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(subclass1,
imports(interface),
specializes(public::root)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(subclass2,
imports(interface),
specializes(protected::root)).
:- end_object.

View File

@ -0,0 +1,7 @@
:- object(subclass3,
imports(interface),
specializes(private::root)).
:- end_object.

View File

@ -0,0 +1,14 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this example consult the instmethods.loader utility
file (note that the *.loader files are Prolog files).
This folder contains an example of instance defined methods. When using
classes and instances, methods must be declared in a class but the method
definitions may be stored in the instances, either overriding or specializing
the class definitions.

View File

@ -0,0 +1,36 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% instance1 definition for method "method" is found in its class:
| ?- instance1::method.
This is the default definition for the method, stored in class root.
yes
% instance2 overrides definition of method "method"
| ?- instance2::method.
This is an overriding definition stored in the instance2 instance itself.
yes
% instance3 specializes definition of method "method"
| ?- instance3::method.
This is a specializing definition stored in the instance3 instance itself.
It makes a super call to execute the default definition:
This is the default definition for the method, stored in class root.
yes

View File

@ -0,0 +1,6 @@
:- object(instance1,
instantiates(root)).
:- end_object.

View File

@ -0,0 +1,13 @@
:- object(instance2,
instantiates(root)).
method :-
this(This),
write('This is an overriding definition stored in the '),
writeq(This),
write(' instance itself.'), nl.
:- end_object.

View File

@ -0,0 +1,15 @@
:- object(instance3,
instantiates(root)).
method :-
this(This),
write('This is a specializing definition stored in the '),
writeq(This),
write(' instance itself.'), nl,
write('It makes a super call to execute the default definition:'), nl, nl,
^^method.
:- end_object.

View File

@ -0,0 +1,7 @@
:- initialization(
logtalk_load([
root,
instance1,
instance2,
instance3])).

View File

@ -0,0 +1,15 @@
:- object(root,
instantiates(root)).
:- public(method/0).
method :-
this(This),
write('This is the default definition for the method, stored in class '),
writeq(This), write('.'), nl.
:- end_object.

15
Logtalk/examples/lo/NOTES Normal file
View File

@ -0,0 +1,15 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
The examples in this folder are adopted from the Logic&Objects system
by Francis G. McCabe. Detailed descriptions and the original source code
can be found on the book "Logic and Objects" by the author published by
Prentice Hall.
Note that because Logtalk lacks the functional notation of the
Logic&Objects system, my adaptation of the book examples may have
introduced some bugs not present in the original code.

View File

@ -0,0 +1,14 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
This example is an adaptation of a LPA Prolog++ example.
To load all objects in this example consult the lpa.loader utility
file.
You will also need to consult the library/hierarchies.loader file.
Note that the *.loader files are Prolog files.

View File

@ -0,0 +1,21 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
| ?- fault::findall.
Please answer all questions with yes or no.
The starter turns but the engine doesnt fire? no.
The engine has difficulty starting? yes.
The engine cuts out shortly after starting? yes.
Location : distributor
Possible Fault: Worn distributor brushes
No (more) explanations found.
yes.

View File

@ -0,0 +1,6 @@
:- object(cylinders,
extends(engine)).
:- end_object.

View File

@ -0,0 +1,25 @@
:- object(distributor,
extends(sparking)).
fault(f1001, 'Condensation in the distributor cap').
fault(f1002, 'Faulty distributor arm').
fault(f1003, 'Worn distributor brushes').
symptom(s1001, 'The starter turns but the engine doesnt fire').
symptom(s1002, 'The engine has difficulty starting').
symptom(s1003, 'The engine cuts out shortly after starting').
symptom(s1004, 'The engine cuts out at speed').
effect(f1001, s1001).
effect(f1002, s1001).
effect(f1002, s1004).
effect(f1003, s1002).
effect(f1003, s1003).
contrary(s1002, s1001).
contrary(s1003, s1001).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(electrical,
extends(fault)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(engine,
extends(mechanical)).
:- end_object.

View File

@ -0,0 +1,72 @@
:- object(fault,
imports(proto_hierarchy)).
:- info([
authors is 'Paulo Moura',
version is 1.0,
date is 2000/4/22,
comment is 'Expert system for automobile fault diagnosis.',
source is 'Example adopted from the LPA Prolog++ documentation.']).
:- public(findall/0).
:- mode(findall, one).
:- private(told_by_user_/2).
:- dynamic(told_by_user_/2).
:- mode(told_by_user_(?nonvar, ?nonvar), zero_or_more).
:- public(find/1).
:- mode(find(?nonvar), zero_or_more).
:- private(exhibited/1).
:- mode(exhibited(+nonvar), zero_or_one).
:- public(contrary/2).
:- mode(contrary(?nonvar, ?nonvar), zero_or_more).
:- public(fault/2).
:- mode(fault(?nonvar, ?nonvar), zero_or_more).
:- public(effect/2).
:- mode(effect(?nonvar, ?nonvar), zero_or_more).
:- public(symptom/2).
:- mode(symptom(?nonvar, ?nonvar), zero_or_more).
findall :-
retractall(told_by_user_(_, _)),
write('Please answer all questions with yes or no.'), nl, nl,
forall(
(::descendant(Where), Where::find(Description)),
(nl, write('Location : '), write(Where), nl,
write('Possible Fault: '), write(Description), nl)),
nl, write('No (more) explanations found.').
find(Description) :-
::fault(Fault, Description),
forall(::effect(Fault, Symptom), exhibited(Symptom)).
exhibited(Symptom) :-
told_by_user_(Symptom, Reply),
!,
Reply = yes.
exhibited(Symptom) :-
::symptom(Symptom, Description),
write(Description), write('? '),
read(Reply),
asserta(told_by_user_(Symptom, Reply)),
Reply = yes,
forall(
(::contrary(Symptom, Contrary);
::contrary(Contrary, Symptom)),
asserta(told_by_user_(Contrary, no))).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(fuel_system,
extends(fault)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(lights,
extends(electrical)).
:- end_object.

View File

@ -0,0 +1,15 @@
:- initialization(
logtalk_load([
cylinders,
distributor,
electrical,
engine,
fault,
fuel_system,
lights,
mechanical,
plugs,
sparking,
starter_motor,
starting])).

View File

@ -0,0 +1,6 @@
:- object(mechanical,
extends(fault)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(plugs,
extends(sparking)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(sparking,
extends(starting)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(starter_motor,
extends(starting)).
:- end_object.

View File

@ -0,0 +1,6 @@
:- object(starting,
extends(electrical)).
:- end_object.

View File

@ -0,0 +1,16 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
To load all objects in this library consult the metapredicates.loader utility
file.
You will also need to load the library/types.loader file (note that the
*.loader files are Prolog files).
This example shows the use of metapredicates in Logtalk. Metapredicates are
predicates whose head contains arguments that will be called as goals in the
body of the predicate definition.

View File

@ -0,0 +1,48 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.8.4
Copyright (c) 1998-2001 Paulo Moura. All Rights Reserved.
=================================================================
% note that "user" is a pseudo-object representing the Prolog database
% this implies that the integer comparisons are done using the standard
% Prolog built-in predicates
| ?- sort(user)::sort([3, 1, 4, 2, 9], Sorted).
call: partition([1,4,2,9],3,_358,_359)
exit: partition([1,4,2,9],3,[1,2],[4,9])
call: sort([1,2],_740)
call: partition([2],1,_967,_968)
exit: partition([2],1,[],[2])
call: sort([],_1300)
exit: sort([],[])
call: sort([2],_1539)
call: partition([],2,_1765,_1766)
exit: partition([],2,[],[])
call: sort([],_2093)
exit: sort([],[])
call: sort([],_2332)
exit: sort([],[])
exit: sort([2],[2])
exit: sort([1,2],[1,2])
call: sort([4,9],_2831)
call: partition([9],4,_3058,_3059)
exit: partition([9],4,[],[9])
call: sort([],_3391)
exit: sort([],[])
call: sort([9],_3630)
call: partition([],9,_3856,_3857)
exit: partition([],9,[],[])
call: sort([],_4184)
exit: sort([],[])
call: sort([],_4423)
exit: sort([],[])
exit: sort([9],[9])
exit: sort([4,9],[4,9])
Sorted = [1,2,3,4,9] ?
yes

View File

@ -0,0 +1,5 @@
:- initialization(
logtalk_load([
sort1,
tracer])).

View File

@ -0,0 +1,61 @@
% sort code adopted from an example in the SICStus Prolog User Manual
% metapredicate example taken from Prolog Part 2, Modules - Committee Draft
:- object(sort(_Type)).
:- info([
version is 1.0,
authors is 'Paulo Moura',
date is 2000/7/24,
comment is 'List sorting parameterized by the type of the list elements.']).
:- uses(list).
:- uses(tracer).
:- calls(comparingp).
:- public(sort/2).
:- mode(sort(+list, -list), one).
:- info(sort/2, [
comment is 'Sorts a list in ascending order.',
argnames is ['List', 'Sorted']]).
:- private(partition/4).
:- mode(partition(+list, +nonvar, -list, -list), one).
:- info(partition/4, [
comment is 'Partition a list in two lists containing the elements smaller and larger than a pivot.',
argnames is ['List', 'Pivot', 'Small', 'Large']]).
sort([], []).
sort([Head| Tail], Sorted) :-
tracer::(
trace(partition(Tail, Head, Small, Large)),
trace(sort(Small, Sorted1)),
trace(sort(Large, Sorted2))),
list::append(Sorted1, [Head| Sorted2], Sorted).
partition([], _, [], []).
partition([Head| Tail], Pivot, Small, Large) :-
parameter(1, Type),
( Type::(Head < Pivot) ->
Small = [Head| Small1], Large = Large1
; Small = Small1, Large = [Head| Large1]
),
partition(Tail, Pivot, Small1, Large1).
:- end_object.

View File

@ -0,0 +1,37 @@
% example adopted from:
% Programming Language Prolog Part 2, Modules
% Committee Draft - January 14, 1998 X3J17/97/5
:- object(tracer).
:- info([
version is 2,
authors is 'Paulo Moura',
date is 2000/7/24,
comment is 'Tracer for a goal call and exit ports.']).
:- public(trace/1).
:- metapredicate(trace(::)).
:- mode(trace(+callable), zero_or_more).
:- info(trace/1, [
comment is '.',
argnames is ['Goal']]).
trace(Goal) :-
write('call: '), writeq(Goal), nl,
call(Goal),
write('exit: '), writeq(Goal), nl.
trace(Goal) :-
write('fail: '), writeq(Goal), nl,
fail.
:- end_object.

Some files were not shown because too many files have changed in this diff Show More