docs
This commit is contained in:
parent
bc6bf8cdfd
commit
53877ad426
@ -16,7 +16,7 @@
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/** @defgroup YAPArrays Arrays
|
||||
/** @defgroup YAPArrays Named Arrays
|
||||
@ingroup YAPExtensions
|
||||
@{
|
||||
|
||||
|
@ -20,7 +20,7 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
/**
|
||||
|
||||
@defgroup Syntax YAP Syntax
|
||||
@defgroup YAPSyntax YAP Syntax
|
||||
@ingroup YAPProgramming
|
||||
@{
|
||||
|
||||
|
11
H/eval.h
11
H/eval.h
@ -21,7 +21,7 @@
|
||||
|
||||
@ingroup YAPBuiltins
|
||||
|
||||
+ See @ref arithmetic_preds for the predicates that implement arithment
|
||||
+ See @ref arithmetic_preds for the predicates that implement arithment
|
||||
|
||||
+ See @ref arithmetic_cmps for the arithmetic comparisons supported in YAP
|
||||
|
||||
@ -58,8 +58,8 @@ quotients of two integers. Rational arithmetic is provided if GMP is
|
||||
used. Rational numbers that are returned from is/2 are canonical,
|
||||
which means the denominator _M_ is positive and that the numerator _N_
|
||||
and _M_ have no common divisors. Rational numbers are introduced in
|
||||
the computation using the [rational/1][@ref rational_1],
|
||||
[rationalize/1][@ref rationalize/1] or the [rdiv/2][@ref rdiv/2]
|
||||
the computation using the rational/1,
|
||||
rationalize/1 or the rdiv/2
|
||||
(rational division) function.
|
||||
|
||||
</li>
|
||||
@ -67,9 +67,8 @@ the computation using the [rational/1][@ref rational_1],
|
||||
|
||||
Floating point numbers are represented using the C-type double. On
|
||||
most today platforms these are 64-bit IEEE-754 floating point
|
||||
numbers. YAP now includes the built-in predicates [isinf/1][@ref isinf/1] and to [isnan/1][@ref isnan/1] tests.
|
||||
</li>
|
||||
</ul>
|
||||
numbers. YAP now includes the built-in predicates isinf/1 and to
|
||||
isnan/1 tests. </li> </ul>
|
||||
|
||||
Arithmetic functions that require integer arguments accept, in addition
|
||||
to integers, rational numbers with denominator `1' and floating point
|
||||
|
@ -1,8 +1,5 @@
|
||||
/**
|
||||
|
||||
@defgroup CHR CHR: Constraint Handling Rules
|
||||
|
||||
@ingroup SWILibrary
|
||||
CHR: Constraint Handling Rules {#chr}
|
||||
==============================
|
||||
|
||||
This chapter is written by Tom Schrijvers, K.U. Leuven for the hProlog
|
||||
system. Adjusted by Jan Wielemaker to fit the SWI-Prolog documentation
|
||||
@ -527,4 +524,4 @@ Provide mode and type declarations to get more efficient program execution.
|
||||
Make sure to disable debug (`-nodebug`) and enable optimization
|
||||
(`-O`).
|
||||
|
||||
*/
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
Constraint Logic Programming over Rationals and Reals {#clpqr}
|
||||
=====================================================
|
||||
|
||||
@defgroup clpr Constraint Logic Programming over Rationals and Reals
|
||||
@ingroup SWILibrary
|
||||
@{
|
||||
|
||||
YAP now uses the CLP(R) package developed by <em>Leslie De Koninck</em>,
|
||||
K.U. Leuven as part of a thesis with supervisor Bart Demoen and daily
|
||||
@ -24,17 +23,12 @@ explicitely before using it:
|
||||
:- use_module(library(clpr)).
|
||||
~~~~~
|
||||
|
||||
@defgroup CLPR_Solver_Predicates Solver Predicates
|
||||
@ingroup clpr
|
||||
@{
|
||||
|
||||
### Solver Predicates {#CLPQR_Solver_Predicates}
|
||||
|
||||
The following predicates are provided to work with constraints:
|
||||
|
||||
|
||||
* @defgroup CLPR_Syntax Syntax of the predicate arguments
|
||||
@ingroup YAPPackages
|
||||
@{
|
||||
### Syntax of the predicate arguments {#CLPQR_Syntax}
|
||||
|
||||
|
||||
The arguments of the predicates defined in the subsection above are
|
||||
@ -74,11 +68,8 @@ result in an exception.
|
||||
| max(<Expression>, <Expression>) \ maximum \
|
||||
~~~~~
|
||||
|
||||
@}
|
||||
|
||||
@defgroup CLPR_Unification Use of unification
|
||||
@ingroup clpr
|
||||
@{
|
||||
### Use of unification {#CLPQR_Unification}
|
||||
|
||||
Instead of using the `{}/1` predicate, you can also use the standard
|
||||
unification mechanism to store constraints. The following code samples
|
||||
@ -101,11 +92,7 @@ X = 5.0
|
||||
~~~~~
|
||||
|
||||
|
||||
@}
|
||||
|
||||
@defgroup CLPR_NonhYlinear_Constraints Non-Linear Constraints
|
||||
@ingroup clpr
|
||||
@{
|
||||
#### Non-Linear Constraints {#CLPQR_NonhYlinear_Constraints}
|
||||
|
||||
|
||||
In this version, non-linear constraints do not get solved until certain
|
||||
@ -132,7 +119,3 @@ X = cos(Y) Y is ground // X = sin(1.5707)
|
||||
X = tan(Y)
|
||||
~~~~~
|
||||
|
||||
@}
|
||||
|
||||
@}
|
||||
|
||||
|
@ -228,7 +228,7 @@ TAB_SIZE = 4
|
||||
# "Side Effects:". You can put \n's in the value part of an alias to insert
|
||||
# newlines.
|
||||
|
||||
ALIASES = "predicate=@brief" "license=@par License:\n" "doxygen=\if english" "endenglish=\endif" "dutch=\if dutch" "enddutch=\endif"
|
||||
ALIASES = "predicate=@brief" "license=@par License:\n" "doxygen=\if english" "endenglish=\endif" "dutch=\if dutch" "enddutch=\endif" "tbd=@par TBD:\n" "compat=@par Compatibility:\n" "error=@par Error:\n" "t= "
|
||||
|
||||
# This tag can be used to specify a number of word-keyword mappings (TCL only).
|
||||
# A mapping has the form "name=value". For example adding "class=itcl::class"
|
||||
@ -678,7 +678,7 @@ FILE_VERSION_FILTER =
|
||||
# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
|
||||
# tag is left empty.
|
||||
|
||||
LAYOUT_FILE =
|
||||
LAYOUT_FILE = # docs/DoxygenLayout.xml
|
||||
|
||||
# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
|
||||
# the reference definitions. This must be a list of .bib files. The .bib
|
||||
@ -767,9 +767,11 @@ WARN_LOGFILE =
|
||||
# INPUT = /Users/vsc/git/yap-6.3/packages/real/real.pl
|
||||
#INPUT = /Users/vsc/git/yap-6.3/packages/cplint/mcintyre.pl
|
||||
# INPUT = /Users/vsc/git/yap-6.3/packages/cplint/mcintyre.pl
|
||||
#INPUT = /Users/vsc/git/yap-6.3/packages/R/R.pl
|
||||
#Input = /Users/vsc/git/0yap-6.3/packages/R/R.pl
|
||||
|
||||
INPUT = docs/yap.md pl swi C H include os packages library CXX OPTYap
|
||||
INPUT = tmp/foreigns.yap docs/yap.md pl swi C H include os packages library CXX OPTYap
|
||||
|
||||
# INPUT = docs/yap.md swi/library/aggregate.pl
|
||||
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
@ -1062,7 +1064,7 @@ HTML_FILE_EXTENSION = .html
|
||||
# of the possible markers and block names see the documentation.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_HEADER =
|
||||
HTML_HEADER = # docs/new_header.html
|
||||
|
||||
# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
|
||||
# generated HTML page. If the tag is left blank doxygen will generate a standard
|
||||
@ -1072,7 +1074,7 @@ HTML_HEADER =
|
||||
# that doxygen normally uses.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_FOOTER =
|
||||
HTML_FOOTER = # docs/new_footer.html
|
||||
|
||||
# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
|
||||
# sheet that is used by each HTML page. It can be used to fine-tune the look of
|
||||
@ -1095,7 +1097,7 @@ HTML_STYLESHEET =
|
||||
# see the documentation.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
HTML_EXTRA_STYLESHEET =
|
||||
HTML_EXTRA_STYLESHEET = # docs/new_stylesheet.css
|
||||
|
||||
# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
|
||||
# other source files which should be copied to the HTML output directory. Note
|
||||
@ -1942,7 +1944,7 @@ SEARCH_INCLUDES = YES
|
||||
# preprocessor.
|
||||
# This tag requires that the tag SEARCH_INCLUDES is set to YES.
|
||||
|
||||
INCLUDE_PATH =
|
||||
INCLUDE_PATH = H
|
||||
|
||||
# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
|
||||
# patterns (like *.h and *.hpp) to filter out the header-files in the
|
||||
|
@ -1,6 +1,4 @@
|
||||
@defgroup Syntax YAP Syntax
|
||||
@ingroup YAPProgramming
|
||||
@{
|
||||
@defgroup YAPSyntax YAP Syntax
|
||||
|
||||
We will describe the syntax of YAP at two levels. We first will
|
||||
describe the syntax for Prolog terms. In a second level we describe
|
||||
|
49
docs/yap.bib
49
docs/yap.bib
@ -11,3 +11,52 @@
|
||||
Year =1986
|
||||
}
|
||||
|
||||
@inproceedings{DBLP:conf/cl/GrasH00,
|
||||
author = {Daniel Cabeza Gras and
|
||||
Manuel V. Hermenegildo},
|
||||
title = {A New Module System for Prolog},
|
||||
booktitle = {Computational Logic - {CL} 2000, First International Conference, London,
|
||||
UK, 24-28 July, 2000, Proceedings},
|
||||
pages = {131--148},
|
||||
year = {2000},
|
||||
crossref = {DBLP:conf/cl/2000},
|
||||
url = {http://dx.doi.org/10.1007/3-540-44957-4_9},
|
||||
doi = {10.1007/3-540-44957-4_9},
|
||||
timestamp = {Tue, 21 Jun 2011 16:38:43 +0200},
|
||||
biburl = {http://dblp.uni-trier.de/rec/bib/conf/cl/GrasH00},
|
||||
bibsource = {dblp computer science bibliography, http://dblp.org}
|
||||
}
|
||||
@proceedings{DBLP:conf/cl/2000,
|
||||
editor = {John W. Lloyd and
|
||||
Ver{\'{o}}nica Dahl and
|
||||
Ulrich Furbach and
|
||||
Manfred Kerber and
|
||||
Kung{-}Kiu Lau and
|
||||
Catuscia Palamidessi and
|
||||
Lu{\'{\i}}s Moniz Pereira and
|
||||
Yehoshua Sagiv and
|
||||
Peter J. Stuckey},
|
||||
title = {Computational Logic - {CL} 2000, First International Conference, London,
|
||||
UK, 24-28 July, 2000, Proceedings},
|
||||
series = {Lecture Notes in Computer Science},
|
||||
volume = {1861},
|
||||
publisher = {Springer},
|
||||
year = {2000},
|
||||
isbn = {3-540-67797-6},
|
||||
timestamp = {Thu, 03 Jan 2002 11:55:20 +0100},
|
||||
biburl = {http://dblp.uni-trier.de/rec/bib/conf/cl/2000},
|
||||
bibsource = {dblp computer science bibliography, http://dblp.org}
|
||||
}
|
||||
|
||||
|
||||
@Manual{quintus,
|
||||
title = {Quintus {P}rolog v3 User's Manual},
|
||||
author = {{Swedish Institute of Computer Science}},
|
||||
url = {http://www.sics.se/isl/quintus/html/quintus/index.html},
|
||||
organization = {The Intelligent Systems Laboratory},
|
||||
address = {PO Box 1263, S-164 28 Kista, Sweden},
|
||||
year = 2003,
|
||||
bibauthor = {haemmerl -- Feb 20, 2006}
|
||||
}
|
||||
|
||||
|
||||
|
651
docs/yap.md
651
docs/yap.md
@ -1,27 +1,30 @@
|
||||
|
||||
YAP Manual Main Page {#mainpage}
|
||||
====================
|
||||
|
||||
This file documents the YAP Prolog System version 6.3.4, a high-performance Prolog compiler developed at LIACC, Universidade do Porto. YAP is based on David H. D. Warren's WAM (Warren Abstract Machine), with several optimizations for better performance. YAP follows the Edinburgh tradition, and is largely compatible with DEC-10 Prolog, Quintus Prolog, and especially with C-Prolog.
|
||||
|
||||
+ @ref DownloadInstall
|
||||
+ @ref install
|
||||
|
||||
+ @ref Run
|
||||
+ @ref run
|
||||
|
||||
+ @ref YAPLoading
|
||||
+ @ref consult
|
||||
|
||||
+ @ref YAPBuiltins
|
||||
+ @ref builtins
|
||||
|
||||
+ @ref YAPExtensions
|
||||
+ @ref extensions
|
||||
|
||||
+ @ref YAPProgramming
|
||||
|
||||
+ @ref ChYInterface
|
||||
+ @ref library
|
||||
|
||||
+ @ref YAPLibrary
|
||||
|
||||
+ @ref SWILibrary
|
||||
+ @ref packages
|
||||
|
||||
+ @ref swi
|
||||
|
||||
+ @ref Packages
|
||||
|
||||
|
||||
+ @ref YAPProgramming
|
||||
|
||||
+ @ref fli
|
||||
|
||||
|
||||
|
||||
\author Vitor Santos Costa,
|
||||
\author Luís Damas,
|
||||
\author Rogério Reis
|
||||
@ -42,7 +45,7 @@ us to include his text in this document.
|
||||
|
||||
\endhtmlonly
|
||||
|
||||
@section Intro Introduction
|
||||
== Introduction
|
||||
|
||||
This document provides User information on version 6.3.4 of
|
||||
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
|
||||
@ -168,13 +171,10 @@ Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho.
|
||||
+ YAP includes the `yap2swi` library that ports to YAP code from
|
||||
of SWI's PL interface. This includes the Input/Output Layer, the SWI
|
||||
Foreign Language Interface, and the RDF, archive, clib, http, odbc, plunit,
|
||||
semweb, sgml, and zlib packages written by Jan Wielemaker. Please do refer to the SWI-Prolog home page:
|
||||
|
||||
<http://www.swi-prolog.org>
|
||||
|
||||
for more information on SWI-Prolog and the SWI packages.
|
||||
|
||||
@page DownloadInstall Downloading, Compiling, and Installing YAP
|
||||
semweb, sgml, and zlib packages written by Jan Wielemaker.
|
||||
|
||||
Installing YAP {#install}
|
||||
==============
|
||||
|
||||
The latest development version of Yap-6 is yap-6.3.4 and can be
|
||||
obtained from the repositories
|
||||
@ -198,7 +198,7 @@ Most of these repositories are basically copies of the original
|
||||
repositories at the SWI-Prolog site. YAP-6 will work either with or
|
||||
without these packages.
|
||||
|
||||
@section CompilingYAP Compiling YAP
|
||||
### Compiling YAP {#CompilingYAP}
|
||||
|
||||
To compile YAP it should be sufficient to:
|
||||
|
||||
@ -224,7 +224,7 @@ To compile YAP it should be sufficient to:
|
||||
5 In most systems you will need to be superuser in order to do
|
||||
`make install` and `make info` on the standard directories.
|
||||
|
||||
@section Configuration_Options Tuning the Functionality of YAP
|
||||
### Tuning the Functionality of YAP
|
||||
|
||||
Compiling YAP with the standard options give you a plain vanilla
|
||||
Prolog. You can tune YAP to include extra functionality by calling
|
||||
@ -279,7 +279,7 @@ at runtime using the flag [max_threads](@ref max_threads)).
|
||||
|
||||
Next section discusses machine dependent details.
|
||||
|
||||
@section Machine_Options Tuning YAP for a Particular Machine and Compiler
|
||||
#### Tuning YAP for a Particular Machine and Compiler {#Machine_Options}
|
||||
|
||||
The default options should give you best performance under
|
||||
`GCC`. Although the system is tuned for this compiler
|
||||
@ -287,7 +287,7 @@ we have been able to compile versions of YAP under lcc in Linux,
|
||||
Sun's cc compiler, IBM's xlc, SGI's cc, and Microsoft's Visual C++
|
||||
6.0.
|
||||
|
||||
@section Tuning_for_GCC Tuning YAP for `GCC`.
|
||||
###### Tuning YAP for `GCC`. {#Tuning_for_GCC}
|
||||
|
||||
YAP has been developed to take advantage of `GCC` (but not to
|
||||
depend on it). The major advantage of `GCC` is threaded code and
|
||||
@ -369,7 +369,7 @@ CC="gcc -mabi=64" ./configure --...
|
||||
Be careful. At least for some versions of `GCC`, compiling with
|
||||
`-g` seems to result in broken code.
|
||||
|
||||
@section Compiling_under_mingw Compiling Under MINGW's GCC
|
||||
#### Compiling Under MINGW's GCC {#Compiling_under_mingw}
|
||||
|
||||
|
||||
AT the time of this writing (Nov 2014), YAP uses the mkwin script to
|
||||
@ -431,7 +431,7 @@ tested to develop YAP:
|
||||
wine64. wine32 is distributed with package managers such as ports
|
||||
and brew.
|
||||
|
||||
=== Setting up WIN32 compilation
|
||||
##### Setting up WIN32 compilation
|
||||
|
||||
Compiling WIN32 packages depends on a number of parameters: chosen compiler,
|
||||
packages to install, directory setup. You may have to change these ones that
|
||||
@ -455,11 +455,11 @@ control the `mkwin` script:
|
||||
* `R`: R environment package, usually in the distribution.
|
||||
* `GECODE`: constraint solver package, usually not in the WIN32 distribution.
|
||||
|
||||
@subsection Compiling_Under_Visual_C Compiling Under Visual C++
|
||||
##### Compiling Under Visual C++ {#Compiling_Under_Visual_C}
|
||||
|
||||
YAP used to compile cleanly under Microsoft's Visual C++ release 6.0. We next
|
||||
give a step-by-step review on how the core YAP compiled manually using this
|
||||
environment.
|
||||
environment. Newer versions of YAP will use cmake for this purpose.
|
||||
|
||||
First, it is a good idea to build YAP as a DLL:
|
||||
|
||||
@ -557,26 +557,38 @@ That's it, you've got YAP and the saved state!
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
The $YAPSRC\\VC directory has the make files to build YAP4.3.17 under VC++ 6.0.
|
||||
Loading and Organising YAP Programs {#consult}
|
||||
===================================
|
||||
|
||||
@subsection Tuning_for_SGI_cc Compiling Under SGI's cc
|
||||
@ingroup main
|
||||
|
||||
Next, we present the main predicates and directives available to load
|
||||
files and to control the Prolog environment.
|
||||
|
||||
YAP should compile under the Silicon Graphic's `cc` compiler,
|
||||
although we advise using the GNUCC compiler, if available.
|
||||
+ \subpage YAPConsulting
|
||||
|
||||
+ 64 bit
|
||||
Support for 64 bits should work by using (under Bourne shell syntax):
|
||||
+ \subpage YAPModules
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
CC="cc -64" $YAP_SRC_PATH/configure --...
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
+ \subpage YAPSaving
|
||||
|
||||
|
||||
@page Run Running YAP
|
||||
This chapter describes the predicates for controlling the execution of
|
||||
Prolog programs.
|
||||
|
||||
In the description of the arguments of functors the following notation
|
||||
will be used:
|
||||
|
||||
+ a preceding plus sign will denote an argument as an "input
|
||||
argument" - it cannot be a free variable at the time of the call;
|
||||
+ a preceding minus sign will denote an "output argument";
|
||||
+ an argument with no preceding symbol can be used in both ways.
|
||||
|
||||
Running YAP {#run}
|
||||
===========
|
||||
|
||||
We next describe how to invoke YAP in Unix systems.
|
||||
|
||||
@section Running_YAP_Interactively Running YAP Interactively
|
||||
#### Running YAP Interactively
|
||||
|
||||
Most often you will want to use YAP in interactive mode. Assuming that
|
||||
YAP is in the user's search path, the top-level can be invoked under
|
||||
@ -667,7 +679,7 @@ YAP will try to find library files from the YAPSHAREDIR/library
|
||||
directory.
|
||||
|
||||
|
||||
@section Running_Prolog_Files Running Prolog Files
|
||||
#### Prolog Scripts
|
||||
|
||||
YAP can also be used to run Prolog files as scripts, at least in
|
||||
Unix-like environments. A simple example is shown next (do not forget
|
||||
@ -761,231 +773,124 @@ they must be sent directly to the argv built-in. Hence, running
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
will write `test` on the standard output.
|
||||
|
||||
YAP Built-ins {#builtins}
|
||||
=============
|
||||
|
||||
@defgroup YAPLoading Loading and Organising YAP Programs
|
||||
+ @ref YAPControl
|
||||
|
||||
@page LoadingInYap Using YAP Programs
|
||||
+ @ref arithmetic
|
||||
|
||||
Next, we present the main predicates and directives available to load
|
||||
files and to control the Prolog environment.
|
||||
+ @ref YAPChars
|
||||
|
||||
+ \subpage YAPConsulting
|
||||
+ @ref YAP_Terms
|
||||
|
||||
+ \subpage YAPModules
|
||||
+ @ref InputOutput
|
||||
|
||||
+ \subpage YAPSaving
|
||||
+ @ref YAPOS
|
||||
|
||||
+ @ref Internal_Database
|
||||
|
||||
This chapter describes the predicates for controlling the execution of
|
||||
Prolog programs.
|
||||
+ @ref Sets
|
||||
|
||||
In the description of the arguments of functors the following notation
|
||||
will be used:
|
||||
Extensions to core Prolog. {#extensions}
|
||||
==========================
|
||||
|
||||
+ a preceding plus sign will denote an argument as an "input
|
||||
argument" - it cannot be a free variable at the time of the call;
|
||||
+ a preceding minus sign will denote an "output argument";
|
||||
+ an argument with no preceding symbol can be used in both ways.
|
||||
YAP includes a number of extensions over the original Prolog
|
||||
language. Next, we discuss how to use the most important ones.
|
||||
|
||||
@defgroup YAPBuiltins YAP Built-Ins
|
||||
|
||||
@page Core Prolog Built-Ins
|
||||
|
||||
+ @ref YAPControl
|
||||
|
||||
+ @ref arithmetic
|
||||
|
||||
+ @ref YAPChars
|
||||
|
||||
+ @ref YAP_Terms
|
||||
|
||||
+ @ref InputOutput
|
||||
|
||||
+ @ref YAPOS
|
||||
|
||||
+ @ref Internal_Database
|
||||
|
||||
+ @ref Sets
|
||||
|
||||
+ @ref Grammars
|
||||
|
||||
+ @ref Term_Modification
|
||||
|
||||
+ @ref LoadForeign
|
||||
|
||||
+ @ref Predicates_on_Atoms
|
||||
|
||||
+ @ref Flags
|
||||
|
||||
+ @ref Deb_Preds
|
||||
|
||||
@defgroup ChYInterface Foreign Language interface to YAP
|
||||
|
||||
YAP provides the user with three facilities for writing
|
||||
predicates in a language other than Prolog. Under Unix systems,
|
||||
most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface.
|
||||
This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is
|
||||
being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
+ The @ref c-interface exports the YAP engine.
|
||||
+ The @ref swi-c-interface emulates Jan Wielemaker's SWI foreign language interface.
|
||||
+ The @ref yap-cplus-interface is desiged to interface with Object-Oriented systems.
|
||||
|
||||
@defgroup YAPExtensions Extensions to core Prolog.
|
||||
|
||||
+@ref Rational_Trees
|
||||
+ @ref Rational_Trees
|
||||
|
||||
+ @ref CohYroutining
|
||||
+ @ref CohYroutining
|
||||
|
||||
+ @ref Attributed_Variables
|
||||
+ @ref Attributed_Variables
|
||||
|
||||
+ @ref DepthLimited
|
||||
+ @ref DepthLimited
|
||||
|
||||
+ @ref Tabling
|
||||
+ @ref Tabling
|
||||
|
||||
+ @ref Threads
|
||||
+ @ref Threads
|
||||
|
||||
+ @ref Profiling
|
||||
+ @ref Profiling
|
||||
|
||||
+ @ref YAPArrays
|
||||
+ @ref YAPArrays
|
||||
|
||||
+ @ref Parallelism
|
||||
+ @ref Parallelism
|
||||
|
||||
@defgroup YAPLibrary The YAP Library
|
||||
The YAP Library {#library}
|
||||
===============
|
||||
|
||||
@page LIbrary The YAP Library
|
||||
Library files reside in the library_directory path (set by the
|
||||
`LIBDIR` variable in the Makefile for YAP). Several files in the
|
||||
library are originally from the public-domain Edinburgh Prolog library.
|
||||
|
||||
Library files reside in the library_directory path (set by the
|
||||
`LIBDIR` variable in the Makefile for YAP). Several files in the
|
||||
library are originally from the public-domain Edinburgh Prolog library.
|
||||
+ @ref maplist
|
||||
|
||||
+ @ref maplist
|
||||
+ @ref Apply Apply Macros
|
||||
|
||||
+ @ref Association_Lists
|
||||
|
||||
+ @ref AVL_Trees
|
||||
|
||||
+ @ref Exo_Intervals
|
||||
|
||||
+ @ref Heaps
|
||||
|
||||
+ @ref Lists
|
||||
|
||||
+ @ref LineUtilities
|
||||
|
||||
+ @ref matrix
|
||||
|
||||
+ @ref NonhYBacktrackable_Data_Structures
|
||||
|
||||
+ @ref Ordered_Sets
|
||||
|
||||
+ @ref Pseudo_Random
|
||||
|
||||
+ @ref Queues Queues
|
||||
|
||||
+ @ref PseudoRandom
|
||||
|
||||
+ @ref RedhYBlack_Trees
|
||||
|
||||
+ @ref RegExp
|
||||
|
||||
+ @ref Apply Apply Macros
|
||||
|
||||
+ @ref Association_Lists
|
||||
|
||||
+ @ref AVL_Trees
|
||||
|
||||
+ @ref Exo_Intervals
|
||||
|
||||
+ @ref Heaps
|
||||
|
||||
+ @ref Lists
|
||||
|
||||
+ @ref LineUtilities
|
||||
|
||||
+ @ref matrix
|
||||
|
||||
+ @ref NonhYBacktrackable_Data_Structures
|
||||
|
||||
+ @ref Ordered_Sets
|
||||
|
||||
+ @ref Pseudo_Random
|
||||
|
||||
+ @ref Queues Queues
|
||||
|
||||
+ @ref PseudoRandom
|
||||
|
||||
+ @ref RedhYBlack_Trees
|
||||
|
||||
+ @ref RegExp
|
||||
+ @ref Splay_Trees
|
||||
|
||||
+ @ref System
|
||||
|
||||
+ @ref Terms
|
||||
|
||||
+ @ref Tries
|
||||
|
||||
+ @ref Cleanup
|
||||
|
||||
+ @ref Timeout
|
||||
|
||||
+ @ref Trees
|
||||
|
||||
+ @ref UGraphs
|
||||
|
||||
+ @ref DGraphs
|
||||
|
||||
+ @ref UnDGraphs
|
||||
|
||||
+ @ref DBUsage
|
||||
|
||||
+ @ref lambda
|
||||
|
||||
+ @ref Splay_Trees
|
||||
|
||||
+ @ref System
|
||||
|
||||
+ @ref Terms
|
||||
|
||||
+ @ref Tries
|
||||
|
||||
+ @ref Cleanup
|
||||
|
||||
+ @ref Timeout
|
||||
|
||||
+ @ref Trees
|
||||
|
||||
+ @ref UGraphs
|
||||
|
||||
+ @ref DGraphs
|
||||
|
||||
+ @ref UnDGraphs
|
||||
|
||||
+ @ref DBUsage
|
||||
|
||||
+ @ref lambda
|
||||
+ @ref clpfd
|
||||
|
||||
+ @ref Block_Diagram
|
||||
|
||||
+ @ref clpfd
|
||||
|
||||
+ @ref Block_Diagram
|
||||
|
||||
@defgroup YAPProgramming Programming in YAP
|
||||
|
||||
@page Programming Programming in YAP
|
||||
|
||||
+ @ref Syntax
|
||||
|
||||
+ @ref Indexing
|
||||
|
||||
+ @ref Deb_Interaction
|
||||
|
||||
@defgroup SWILibrary SWI-Prolog Libraries and Packages
|
||||
|
||||
@page SWICode The SWI-Prolog Libraries and Packages
|
||||
|
||||
+ @ref aggregate
|
||||
|
||||
+ @ref date
|
||||
|
||||
+ @ref Print debug messages and test assertions
|
||||
|
||||
+ @ref persistence
|
||||
|
||||
+ @ref pio
|
||||
|
||||
+ @ref predicate_options
|
||||
|
||||
+ @ref prolog_clause
|
||||
|
||||
+ @ref prolog_colour
|
||||
|
||||
+ @ref prolog_main
|
||||
|
||||
+ @ref prolog_source
|
||||
|
||||
+ @ref quasi_quotations
|
||||
|
||||
+ @ref swi_option
|
||||
|
||||
+ @ref read_util
|
||||
|
||||
+ @ref record
|
||||
|
||||
+ @ref settings
|
||||
|
||||
+ @ref shlib
|
||||
|
||||
+ @ref SWIclib
|
||||
|
||||
+ @ref archive
|
||||
|
||||
+ @ref CHR
|
||||
|
||||
+ @ref clpr
|
||||
|
||||
+ @ref http
|
||||
|
||||
+ @ref zlib
|
||||
|
||||
|
||||
@defgroup YAPPackages The YAP packages
|
||||
|
||||
@page Packages The YAP Packages
|
||||
The YAP Packages {#packages}
|
||||
================
|
||||
|
||||
+ @ref real
|
||||
|
||||
|
||||
+ @ref BDDs
|
||||
|
||||
|
||||
+ @ref Gecode
|
||||
|
||||
+ @ref MYDDAS
|
||||
@ -998,41 +903,87 @@ library are originally from the public-domain Edinburgh Prolog library.
|
||||
|
||||
+ @ref YAP-LBFGS
|
||||
|
||||
@defgroup SWIclib The SWI Extended Operating System Support Package
|
||||
@ingroup SWILibrary
|
||||
+ @subpage yap-udi-indexers
|
||||
|
||||
The HTTP package is a series of libraries developed by Jan Wielmaker
|
||||
and the SWI-Prolog community for extended Operating System support.
|
||||
Please consult clib.doc for the complete documentation.
|
||||
Leuven packages ported from SWI-Prolog:
|
||||
|
||||
@defgroup http The SWI http packages
|
||||
@ingroup SWILibrary
|
||||
+ @subpage chr
|
||||
|
||||
The HTTP package is a series of libraries developed by Jan Wielmaker
|
||||
and the SWI-Prolog community for accessing and serving data on the
|
||||
web. It supports lower-level transport protocols, but also
|
||||
data-representation primitives, and more.
|
||||
+ @subpage clpqr
|
||||
|
||||
The port to YAP focussed on the client-side support. The server
|
||||
package has not been as widely tested.
|
||||
|
||||
@page Compatibility Compatibility with Other Prolog systems
|
||||
Compatibility {#swi}
|
||||
=============
|
||||
|
||||
YAP has been designed to be as compatible as possible with
|
||||
other Prolog systems, and initially with C-Prolog. More recent work on
|
||||
YAP has included features initially proposed for the Quintus
|
||||
and SICStus Prolog systems.
|
||||
YAP has been designed to be as compatible as possible with other
|
||||
Prolog systems, originally with C-Prolog\cite x and SICStus
|
||||
Prolog~\cite x . More recent work on YAP has striven at making YAP
|
||||
compatible with the ISO-Prolog standard\cite x , and with Jan
|
||||
Wielemaker's SWI-Prolog\cite x .
|
||||
|
||||
Developments since `YAP4.1.6` we have striven at making
|
||||
YAP compatible with the ISO-Prolog standard.
|
||||
SWI-Prolog and YAP have collaborated at improved compatibility \cite x . This
|
||||
resulted in Prolog extensions such as the `dialect` feature. YAP
|
||||
currently supports most of the SWI-Prolog foreign interface,
|
||||
integrates the SWI I/O code and WIN32 console, and uses several SWI
|
||||
libraries and packages:
|
||||
|
||||
@section ChYProlog Compatibility with the C-Prolog interpreter
|
||||
+ @ref aggregate
|
||||
+ @ref base64
|
||||
+ @ref broadcast
|
||||
+ @ref ctypes
|
||||
+ @ref date
|
||||
+ @ref prolog_debug
|
||||
+ @ref prolog_edit
|
||||
+ @ref error
|
||||
+ @ref nb_set
|
||||
+ @ref prolog_operator
|
||||
+ @ref swi_option
|
||||
+ @ref pairs
|
||||
+ @ref pio
|
||||
+ @ref predicate_options,
|
||||
+ @ref predopts
|
||||
+ @ref prolog_clause
|
||||
+ @ref prolog_colour
|
||||
+ @ref prolog_source
|
||||
+ @ref prolog_xref
|
||||
+ @ref pure_input
|
||||
+ @ref quasi_quotations
|
||||
+ @ref read_util
|
||||
+ @ref record
|
||||
+ @ref settings
|
||||
+ @ref shlib
|
||||
+ @ref thread_pool
|
||||
+ @ref url
|
||||
+ @ref utf8
|
||||
+ @ref win_menu
|
||||
+ @ref www_browser
|
||||
|
||||
@subsection Major_Differences_with_ChYProlog Major Differences between YAP and C-Prolog.
|
||||
The following SWI packages are made available in the SWI distribution:
|
||||
|
||||
YAP includes several extensions over the original C-Prolog system. Even
|
||||
so, most C-Prolog programs should run under YAP without changes.
|
||||
+ @ref archive
|
||||
+ @ref CHR
|
||||
+ @ref clib
|
||||
+ @ref clpqr
|
||||
+ @ref http
|
||||
+ @ref jpl
|
||||
+ @ref odbc
|
||||
+ @ref prosqlite
|
||||
+ @ref zlib
|
||||
|
||||
Note that in general SWI code may be from an earlier version than the
|
||||
one available with SWI-Prolog. SWI-Prolog are obviously not
|
||||
responsible for any incompatibilities and/or bugs in the YAP port.
|
||||
|
||||
Please do refer to the SWI-Prolog home page:
|
||||
|
||||
<http://www.swi-prolog.org>
|
||||
|
||||
for more information on SWI-Prolog and the SWI packages.
|
||||
|
||||
#### Compatibility with the C-Prolog interpreter {#ChYProlog}
|
||||
|
||||
YAP was designed so that most C-Prolog programs should run under YAP
|
||||
without changes.
|
||||
The most important difference between YAP and C-Prolog is that, being
|
||||
YAP a compiler, some changes should be made if predicates such as
|
||||
`assert`, `clause` and `retract` are used. First
|
||||
@ -1068,32 +1019,8 @@ or by using:
|
||||
:- yap_flag(language,cprolog).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@subsection Fully_ChYProlog_Compatible YAP predicates fully compatible with C-Prolog
|
||||
|
||||
These are the Prolog built-ins that are fully compatible in both
|
||||
C-Prolog and YAP:
|
||||
|
||||
@subsection Not_Strictly_ChYProlog_Compatible YAP predicates not strictly compatible with C-Prolog
|
||||
|
||||
These are YAP built-ins that are also available in C-Prolog, but
|
||||
that are not fully compatible:
|
||||
|
||||
@subsection Not_in_ChYProlog YAP predicates not available in C-Prolog
|
||||
|
||||
These are YAP built-ins not available in C-Prolog.
|
||||
|
||||
@subsection Not_in_YAP YAP predicates not available in C-Prolog
|
||||
|
||||
These are C-Prolog built-ins not available in YAP:
|
||||
|
||||
+ 'LC'
|
||||
The following Prolog text uses lower case letters.
|
||||
|
||||
+ 'NOLC'
|
||||
The following Prolog text uses upper case letters only.
|
||||
|
||||
|
||||
@section SICStus_Prolog Compatibility with the Quintus and SICStus Prolog systems
|
||||
#### Compatibility with the Quintus and SICStus Prolog systems
|
||||
|
||||
The Quintus Prolog system was the first Prolog compiler to use Warren's
|
||||
Abstract Machine. This system was very influential in the Prolog
|
||||
@ -1107,131 +1034,25 @@ through several versions. The current version includes several
|
||||
extensions, such as an object implementation, co-routining, and
|
||||
constraints.
|
||||
|
||||
Recent work in YAP has been influenced by work in Quintus and
|
||||
SICStus Prolog. Wherever possible, we have tried to make YAP
|
||||
compatible with recent versions of these systems, and specifically of
|
||||
SICStus Prolog. You should use
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:- yap_flag(language, sicstus).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
for maximum compatibility with SICStus Prolog.
|
||||
|
||||
@subsection Major_Differences_with_SICStus Major Differences between YAP and SICStus Prolog.
|
||||
|
||||
Both YAP and SICStus Prolog obey the Edinburgh Syntax and are based on
|
||||
the WAM. Even so, there are quite a few important differences:
|
||||
the WAM. Even so, there are major important differences:
|
||||
|
||||
+ Differently from SICStus Prolog, YAP does not have a
|
||||
notion of interpreted code. All code in YAP is compiled.
|
||||
|
||||
+ YAP does not support an intermediate byte-code
|
||||
representation, so the `fcompile/1` and `load/1` built-ins are
|
||||
not available in YAP.
|
||||
|
||||
+ YAP implements escape sequences as in the ISO standard. SICStus
|
||||
Prolog implements Unix-like escape sequences.
|
||||
|
||||
+ YAP implements initialization/1 as per the ISO
|
||||
standard. Use prolog_initialization/1 for the SICStus Prolog
|
||||
compatible built-in.
|
||||
|
||||
+ Prolog flags are different in SICStus Prolog and in YAP.
|
||||
|
||||
+ The SICStus Prolog `on_exception/3` and
|
||||
`raise_exception` built-ins correspond to the ISO built-ins
|
||||
catch/3 and throw/1.
|
||||
+ Differently from SICStus Prolog, both consulted and dynamic code in YAP
|
||||
are compiled, not interpreted. All code in YAP is compiled.
|
||||
|
||||
+ The following SICStus Prolog v3 built-ins are not (currently)
|
||||
implemented in YAP (note that this is only a partial list):
|
||||
file_search_path/2,
|
||||
`stream_interrupt/3`, `reinitialize/0`, `help/0`,
|
||||
`help/1`, `trimcore/0`, `load_files/1`,
|
||||
load_files/2, and `require/1`.
|
||||
|
||||
The previous list is incomplete. We also cannot guarantee full
|
||||
compatibility for other built-ins (although we will try to address any
|
||||
such incompatibilities). Last, SICStus Prolog is an evolving system, so
|
||||
one can be expect new incompatibilities to be introduced in future
|
||||
releases of SICStus Prolog.
|
||||
|
||||
+ YAP allows asserting and abolishing static code during
|
||||
execution through the assert_static/1 and abolish/1
|
||||
built-ins. This is not allowed in Quintus Prolog or SICStus Prolog.
|
||||
|
||||
+ The socket predicates, although designed to be compatible with
|
||||
SICStus Prolog, are built-ins, not library predicates, in YAP.
|
||||
|
||||
+ This list is incomplete.
|
||||
|
||||
|
||||
|
||||
The following differences only exist if the language flag is set
|
||||
to `yap` (the default):
|
||||
`stream_interrupt/3`, `reinitialize/0`, `help/0`, `help/1`,
|
||||
`trimcore/0`, and `require/1`.
|
||||
|
||||
+ The consult/1 predicate in YAP follows C-Prolog
|
||||
semantics. That is, it adds clauses to the data base, even for
|
||||
preexisting procedures. This is different from consult/1 in
|
||||
SICStus Prolog or SWI-Prolog.
|
||||
|
||||
+
|
||||
By default, the data-base in YAP follows "logical update semantics", as
|
||||
Quintus Prolog or SICStus Prolog do. Previous versions followed
|
||||
"immediate update semantics". The difference is depicted in the next
|
||||
example:
|
||||
+ This list is incomplete.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:- dynamic a/1.
|
||||
|
||||
?- assert(a(1)).
|
||||
|
||||
?- retract(a(X)), X1 is X +1, assertz(a(X)).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
With immediate semantics, new clauses or entries to the data base are
|
||||
visible in backtracking. In this example, the first call to
|
||||
retract/1 will succeed. The call to *assertz/1* will then
|
||||
succeed. On backtracking, the system will retry
|
||||
retract/1. Because the newly asserted goal is visible to
|
||||
retract/1, it can be retracted from the data base, and
|
||||
`retract(a(X))` will succeed again. The process will continue
|
||||
generating integers for ever. Immediate semantics were used in C-Prolog.
|
||||
|
||||
With logical update semantics, any additions or deletions of clauses
|
||||
for a goal
|
||||
<em>will not affect previous activations of the goal</em>. In the example,
|
||||
the call to assertz/1 will not see the
|
||||
update performed by the assertz/1, and the query will have a
|
||||
single solution.
|
||||
|
||||
Calling `yap_flag(update_semantics,logical)` will switch
|
||||
YAP to use logical update semantics.
|
||||
|
||||
+ dynamic/1 is a built-in, not a directive, in YAP.
|
||||
|
||||
+ By default, YAP fails on undefined predicates. To follow default
|
||||
SICStus Prolog use:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
:- yap_flag(unknown,error).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
+ By default, directives in YAP can be called from the top level.
|
||||
|
||||
@subsection Fully_SICStus_Compatible YAP predicates fully compatible with SICStus Prolog
|
||||
|
||||
These are the Prolog built-ins that are fully compatible in both SICStus
|
||||
Prolog and YAP:
|
||||
|
||||
@subsection Not_Strictly_SICStus_Compatible YAP predicates not strictly compatible with SICStus Prolog
|
||||
|
||||
These are YAP built-ins that are also available in SICStus Prolog, but
|
||||
that are not fully compatible:
|
||||
|
||||
@subsection Not_in_SICStus_Prolog YAP predicates not available in SICStus Prolog
|
||||
|
||||
These are YAP built-ins not available in SICStus Prolog.
|
||||
|
||||
@section ISO_Prolog Compatibility with the ISO Prolog standard
|
||||
#### Compatibility with the ISO Prolog standard
|
||||
|
||||
The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the
|
||||
international standardization working group for the programming language
|
||||
@ -1246,16 +1067,9 @@ ISO-standard, and,
|
||||
|
||||
|
||||
YAP by default is not fully ISO standard compliant. You can set the
|
||||
language flag to `iso` to obtain very good
|
||||
language flag to `iso` to obtain better
|
||||
compatibility. Setting this flag changes the following:
|
||||
|
||||
+ By default, YAP uses "immediate update semantics" for its
|
||||
database, and not "logical update semantics", as per the standard,
|
||||
( (see SICStus Prolog)). This affects assert/1,
|
||||
retract/1, and friends.
|
||||
|
||||
Calling `set_prolog_flag(update_semantics,logical)` will switch
|
||||
YAP to use logical update semantics.
|
||||
|
||||
+ By default, YAP implements the
|
||||
atom_chars/2( (see Testing Terms)), and
|
||||
@ -1278,10 +1092,8 @@ than by default.
|
||||
standard. This feature should disable all features not present in the
|
||||
standard.
|
||||
|
||||
|
||||
|
||||
The following incompatibilities between YAP and the ISO standard are
|
||||
known to still exist:
|
||||
known to still exist (please check Ulrich Neumerkel's page for more details):
|
||||
|
||||
<ul>
|
||||
|
||||
@ -1289,14 +1101,19 @@ known to still exist:
|
||||
operations, and handles floating-point errors only in some
|
||||
architectures. Otherwise, YAP follows IEEE arithmetic.
|
||||
|
||||
|
||||
|
||||
Please inform the authors on other incompatibilities that may still
|
||||
exist.
|
||||
|
||||
## Predicate Index ##
|
||||
Foreign Language interface for YAP {#fli}
|
||||
=================================
|
||||
|
||||
YAP provides the user with three facilities for writing
|
||||
predicates in a language other than Prolog. Under Unix systems,
|
||||
most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface.
|
||||
This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is
|
||||
being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
## Concept Index ##
|
||||
|
||||
+ The @ref c-interface exports the YAP engine.
|
||||
+ The @ref swi-c-interface emulates Jan Wielemaker's SWI foreign language interface.
|
||||
+ The @ref yap-cplus-interface is desiged to interface with Object-Oriented systems.
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
@file YapInterface.h
|
||||
|
||||
@defgroup ChYInterface Foreign Language interface to YAP
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
@ -42,7 +45,7 @@
|
||||
/**
|
||||
|
||||
@defgroup c-interface YAP original C-interface
|
||||
@Ingroup ChYInterface
|
||||
@ingroup ChYInterface
|
||||
|
||||
Before describing in full detail how to interface to C code, we will examine
|
||||
a brief example.
|
||||
@ -206,7 +209,7 @@ YAP_Bool YAP_IsVarTerm(YAP_Term _t_)
|
||||
|
||||
returns true iff its argument is an uninstantiated variable. Conversely the
|
||||
primitive
|
||||
</li>
|
||||
<ul>
|
||||
<li>YAP_Bool YAP_NonVarTerm(YAP_Term _t_)
|
||||
|
||||
returns true iff its argument is not a variable.
|
||||
@ -277,7 +280,7 @@ The set of possible values is an enumerated type, with the following values:
|
||||
</li>
|
||||
<li>`YAP_TAG_FLOAT`: a floating point number
|
||||
</li>
|
||||
<li>`YAP_TAG_OPAQUE`: an opaque term
|
||||
<li>`YAP_TAG_OPAQUE`: an opaque term
|
||||
</li>
|
||||
<li>`YAP_TAG_APPL`: a compound term
|
||||
</li>
|
||||
@ -285,7 +288,7 @@ The set of possible values is an enumerated type, with the following values:
|
||||
|
||||
Next, we mention the primitives that allow one to destruct and construct
|
||||
terms. All the above primitives ensure that their result is
|
||||
\a dereferenced, i.e. that it is not a pointer to another term.
|
||||
a dereferenced, i.e. that it is not a pointer to another term.
|
||||
|
||||
The following primitives are provided for creating an integer term from an
|
||||
integer and to access the value of an integer term.
|
||||
@ -736,7 +739,7 @@ The next functions provides a way to recover the term from the data-base:
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
Notice that the semantics are the same as for [recorded/3](@ref recorded): this
|
||||
Notice that the semantics are the same as for recorded/3: this
|
||||
function creates a new copy of the term in the stack, with fresh
|
||||
variables. The function returns <tt>0L</tt> if it cannot create a new term.
|
||||
|
||||
@ -753,7 +756,7 @@ lead to a crash.
|
||||
The following functions are often required to compare terms.
|
||||
|
||||
Succeed if two terms are actually the same term, as in
|
||||
[==/2](@ref qQqQ):
|
||||
==/2:
|
||||
|
||||
<ul>
|
||||
<li>int YAP_ExactlyEqual(YAP_Term t1, YAP_Term t2)
|
||||
@ -762,7 +765,7 @@ Succeed if two terms are actually the same term, as in
|
||||
|
||||
The next function succeeds if two terms are variant terms, and returns
|
||||
0 otherwise, as
|
||||
[=@=/2](@ref qQaAqQ):
|
||||
=@=/2:
|
||||
|
||||
<ul>
|
||||
<li>int YAP_Variant(YAP_Term t1, YAP_Term t2)
|
||||
@ -789,7 +792,7 @@ The next one returns the length of a well-formed list _t_, or
|
||||
</ul>
|
||||
|
||||
Last, this function succeeds if two terms are unifiable:
|
||||
[=@=/2](@ref qQaAqQ):
|
||||
=@=/2:
|
||||
|
||||
<ul>
|
||||
<li>int YAP_Unifiable(YAP_Term t1, YAP_Term t2)
|
||||
@ -859,7 +862,7 @@ Look for the next solution to the current query by forcing YAP to
|
||||
backtrack to the latest goal. Notice that slots allocated since the last
|
||||
YAP_RunGoal() will become invalid.
|
||||
|
||||
@Item `int` YAP_Reset(`yap_reset_t mode`)
|
||||
<li> `int` YAP_Reset(`yap_reset_t mode`)
|
||||
|
||||
Reset execution environment
|
||||
(similar to the abort/0 built-in). This is useful when
|
||||
@ -1339,7 +1342,7 @@ arguments to the backtrackable procedure.
|
||||
|
||||
|
||||
@defgroup YAPAsLibrary Using YAP as a Library
|
||||
@subgroup c-interface
|
||||
@ingroup c-interface
|
||||
|
||||
YAP can be used as a library to be called from other
|
||||
programs. To do so, you must first create the YAP library:
|
||||
@ -2155,3 +2158,5 @@ extern X_API YAP_Atom YAP_IntToAtom(YAP_Int i);
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
||||
/// @}
|
||||
|
@ -68,6 +68,72 @@
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
|
||||
To make the predicate terminate if any argument is instantiated, add
|
||||
the (implied) constraint F #\= 0 before the recursive call. Otherwise,
|
||||
the query fac(N, 0) is the only non-terminating case of this kind.
|
||||
|
||||
This library uses goal_expansion/2 to rewrite constraints at
|
||||
compilation time. The expansion's aim is to transparently bring the
|
||||
performance of CLP(FD) constraints close to that of conventional
|
||||
arithmetic predicates (</2, =:=/2, is/2 etc.) when the constraints are
|
||||
used in modes that can also be handled by built-in arithmetic. To
|
||||
disable the expansion, set the flag clpfd_goal_expansion to false.
|
||||
|
||||
Use call_residue_vars/2 and copy_term/3 to inspect residual goals and
|
||||
the constraints in which a variable is involved. This library also
|
||||
provides _reflection_ predicates (like fd_dom/2, fd_size/2 etc.) with
|
||||
which you can inspect a variable's current domain. These predicates
|
||||
can be useful if you want to implement your own labeling strategies.
|
||||
|
||||
You can also define custom constraints. The mechanism to do this is
|
||||
not yet finalised, and we welcome suggestions and descriptions of use
|
||||
cases that are important to you. As an example of how it can be done
|
||||
currently, let us define a new custom constraint "oneground(X,Y,Z)",
|
||||
where Z shall be 1 if at least one of X and Y is instantiated:
|
||||
|
||||
==
|
||||
:- use_module(library(clpfd)).
|
||||
|
||||
:- multifile clpfd:run_propagator/2.
|
||||
|
||||
oneground(X, Y, Z) :-
|
||||
clpfd:make_propagator(oneground(X, Y, Z), Prop),
|
||||
clpfd:init_propagator(X, Prop),
|
||||
clpfd:init_propagator(Y, Prop),
|
||||
clpfd:trigger_once(Prop).
|
||||
|
||||
clpfd:run_propagator(oneground(X, Y, Z), MState) :-
|
||||
( integer(X) -> clpfd:kill(MState), Z = 1
|
||||
; integer(Y) -> clpfd:kill(MState), Z = 1
|
||||
; true
|
||||
).
|
||||
==
|
||||
|
||||
First, clpfd:make_propagator/2 is used to transform a user-defined
|
||||
representation of the new constraint to an internal form. With
|
||||
clpfd:init_propagator/2, this internal form is then attached to X and
|
||||
Y. From now on, the propagator will be invoked whenever the domains of
|
||||
X or Y are changed. Then, clpfd:trigger_once/1 is used to give the
|
||||
propagator its first chance for propagation even though the variables'
|
||||
domains have not yet changed. Finally, clpfd:run_propagator/2 is
|
||||
extended to define the actual propagator. As explained, this predicate
|
||||
is automatically called by the constraint solver. The first argument
|
||||
is the user-defined representation of the constraint as used in
|
||||
clpfd:make_propagator/2, and the second argument is a mutable state
|
||||
that can be used to prevent further invocations of the propagator when
|
||||
the constraint has become entailed, by using clpfd:kill/1. An example
|
||||
of using the new constraint:
|
||||
|
||||
==
|
||||
?- oneground(X, Y, Z), Y = 5.
|
||||
Y = 5,
|
||||
Z = 1,
|
||||
X in inf..sup.
|
||||
==
|
||||
|
||||
@author Markus Triska
|
||||
*/
|
||||
|
||||
:- module(clpfd, [
|
||||
op(760, yfx, #<==>),
|
||||
op(750, xfy, #==>),
|
||||
@ -141,208 +207,6 @@
|
||||
:- op(700, xfx, cis_leq).
|
||||
:- op(700, xfx, cis_lt).
|
||||
|
||||
/** <module> Constraint Logic Programming over Finite Domains
|
||||
|
||||
Constraint programming is a declarative formalism that lets you
|
||||
describe conditions a solution must satisfy. This library provides
|
||||
CLP(FD), Constraint Logic Programming over Finite Domains. It can be
|
||||
used to model and solve various combinatorial problems such as
|
||||
planning, scheduling and allocation tasks.
|
||||
|
||||
Most predicates of this library are finite domain _constraints_, which
|
||||
are relations over integers. They generalise arithmetic evaluation of
|
||||
integer expressions in that propagation can proceed in all directions.
|
||||
This library also provides _enumeration_ _predicates_, which let you
|
||||
systematically search for solutions on variables whose domains have
|
||||
become finite. A finite domain _expression_ is one of:
|
||||
|
||||
| an integer | Given value |
|
||||
| a variable | Unknown value |
|
||||
| -Expr | Unary minus |
|
||||
| Expr + Expr | Addition |
|
||||
| Expr * Expr | Multiplication |
|
||||
| Expr - Expr | Subtraction |
|
||||
| min(Expr,Expr) | Minimum of two expressions |
|
||||
| max(Expr,Expr) | Maximum of two expressions |
|
||||
| Expr mod Expr | Remainder of integer division |
|
||||
| abs(Expr) | Absolute value |
|
||||
| Expr / Expr | Integer division |
|
||||
|
||||
The most important finite domain constraints are:
|
||||
|
||||
| Expr1 #>= Expr2 | Expr1 is larger than or equal to Expr2 |
|
||||
| Expr1 #=< Expr2 | Expr1 is smaller than or equal to Expr2 |
|
||||
| Expr1 #= Expr2 | Expr1 equals Expr2 |
|
||||
| Expr1 #\= Expr2 | Expr1 is not equal to Expr2 |
|
||||
| Expr1 #> Expr2 | Expr1 is strictly larger than Expr2 |
|
||||
| Expr1 #< Expr2 | Expr1 is strictly smaller than Expr2 |
|
||||
|
||||
The constraints in/2, #=/2, #\=/2, #</2, #>/2, #=</2, and #>=/2 can be
|
||||
_reified_, which means reflecting their truth values into Boolean
|
||||
values represented by the integers 0 and 1. Let P and Q denote
|
||||
reifiable constraints or Boolean variables, then:
|
||||
|
||||
| #\ Q | True iff Q is false |
|
||||
| P #\/ Q | True iff either P or Q |
|
||||
| P #/\ Q | True iff both P and Q |
|
||||
| P #<==> Q | True iff P and Q are equivalent |
|
||||
| P #==> Q | True iff P implies Q |
|
||||
| P #<== Q | True iff Q implies P |
|
||||
|
||||
The constraints of this table are reifiable as well. If a variable
|
||||
occurs at the place of a constraint that is being reified, it is
|
||||
implicitly constrained to the Boolean values 0 and 1. Therefore, the
|
||||
following queries all fail: ?- #\ 2., ?- #\ #\ 2. etc.
|
||||
|
||||
A common usage of this library is to first post the desired
|
||||
constraints among the variables of a model, and then to use
|
||||
enumeration predicates to search for solutions. As an example of a
|
||||
constraint satisfaction problem, consider the cryptoarithmetic puzzle
|
||||
SEND + MORE = MONEY, where different letters denote distinct integers
|
||||
between 0 and 9. It can be modeled in CLP(FD) as follows:
|
||||
|
||||
==
|
||||
:- use_module(library(clpfd)).
|
||||
|
||||
puzzle([S,E,N,D] + [M,O,R,E] = [M,O,N,E,Y]) :-
|
||||
Vars = [S,E,N,D,M,O,R,Y],
|
||||
Vars ins 0..9,
|
||||
all_different(Vars),
|
||||
S*1000 + E*100 + N*10 + D +
|
||||
M*1000 + O*100 + R*10 + E #=
|
||||
M*10000 + O*1000 + N*100 + E*10 + Y,
|
||||
M #\= 0, S #\= 0.
|
||||
==
|
||||
|
||||
Sample query and its result:
|
||||
|
||||
==
|
||||
?- puzzle(As+Bs=Cs).
|
||||
As = [9, _G10107, _G10110, _G10113],
|
||||
Bs = [1, 0, _G10128, _G10107],
|
||||
Cs = [1, 0, _G10110, _G10107, _G10152],
|
||||
_G10107 in 4..7,
|
||||
1000*9+91*_G10107+ -90*_G10110+_G10113+ -9000*1+ -900*0+10*_G10128+ -1*_G10152#=0,
|
||||
all_different([_G10107, _G10110, _G10113, _G10128, _G10152, 0, 1, 9]),
|
||||
_G10110 in 5..8,
|
||||
_G10113 in 2..8,
|
||||
_G10128 in 2..8,
|
||||
_G10152 in 2..8.
|
||||
==
|
||||
|
||||
Here, the constraint solver has deduced more stringent bounds for all
|
||||
variables. Keeping the modeling part separate from the search lets you
|
||||
view these residual goals, observe termination and determinism
|
||||
properties of the modeling part in isolation from the search, and more
|
||||
easily experiment with different search strategies. Labeling can then
|
||||
be used to search for solutions:
|
||||
|
||||
==
|
||||
?- puzzle(As+Bs=Cs), label(As).
|
||||
As = [9, 5, 6, 7],
|
||||
Bs = [1, 0, 8, 5],
|
||||
Cs = [1, 0, 6, 5, 2] ;
|
||||
false.
|
||||
==
|
||||
|
||||
In this case, it suffices to label a subset of variables to find the
|
||||
puzzle's unique solution, since the constraint solver is strong enough
|
||||
to reduce the domains of remaining variables to singleton sets. In
|
||||
general though, it is necessary to label all variables to obtain
|
||||
ground solutions.
|
||||
|
||||
You can also use CLP(FD) constraints as a more declarative alternative
|
||||
for ordinary integer arithmetic with is/2, >/2 etc. For example:
|
||||
|
||||
==
|
||||
:- use_module(library(clpfd)).
|
||||
|
||||
fac(0, 1).
|
||||
fac(N, F) :- N #> 0, N1 #= N - 1, F #= N * F1, fac(N1, F1).
|
||||
==
|
||||
|
||||
This predicate can be used in all directions. For example:
|
||||
|
||||
==
|
||||
?- fac(47, F).
|
||||
F = 258623241511168180642964355153611979969197632389120000000000 ;
|
||||
false.
|
||||
|
||||
?- fac(N, 1).
|
||||
N = 0 ;
|
||||
N = 1 ;
|
||||
false.
|
||||
|
||||
?- fac(N, 3).
|
||||
false.
|
||||
==
|
||||
|
||||
To make the predicate terminate if any argument is instantiated, add
|
||||
the (implied) constraint F #\= 0 before the recursive call. Otherwise,
|
||||
the query fac(N, 0) is the only non-terminating case of this kind.
|
||||
|
||||
This library uses goal_expansion/2 to rewrite constraints at
|
||||
compilation time. The expansion's aim is to transparently bring the
|
||||
performance of CLP(FD) constraints close to that of conventional
|
||||
arithmetic predicates (</2, =:=/2, is/2 etc.) when the constraints are
|
||||
used in modes that can also be handled by built-in arithmetic. To
|
||||
disable the expansion, set the flag clpfd_goal_expansion to false.
|
||||
|
||||
Use call_residue_vars/2 and copy_term/3 to inspect residual goals and
|
||||
the constraints in which a variable is involved. This library also
|
||||
provides _reflection_ predicates (like fd_dom/2, fd_size/2 etc.) with
|
||||
which you can inspect a variable's current domain. These predicates
|
||||
can be useful if you want to implement your own labeling strategies.
|
||||
|
||||
You can also define custom constraints. The mechanism to do this is
|
||||
not yet finalised, and we welcome suggestions and descriptions of use
|
||||
cases that are important to you. As an example of how it can be done
|
||||
currently, let us define a new custom constraint "oneground(X,Y,Z)",
|
||||
where Z shall be 1 if at least one of X and Y is instantiated:
|
||||
|
||||
==
|
||||
:- use_module(library(clpfd)).
|
||||
|
||||
:- multifile clpfd:run_propagator/2.
|
||||
|
||||
oneground(X, Y, Z) :-
|
||||
clpfd:make_propagator(oneground(X, Y, Z), Prop),
|
||||
clpfd:init_propagator(X, Prop),
|
||||
clpfd:init_propagator(Y, Prop),
|
||||
clpfd:trigger_once(Prop).
|
||||
|
||||
clpfd:run_propagator(oneground(X, Y, Z), MState) :-
|
||||
( integer(X) -> clpfd:kill(MState), Z = 1
|
||||
; integer(Y) -> clpfd:kill(MState), Z = 1
|
||||
; true
|
||||
).
|
||||
==
|
||||
|
||||
First, clpfd:make_propagator/2 is used to transform a user-defined
|
||||
representation of the new constraint to an internal form. With
|
||||
clpfd:init_propagator/2, this internal form is then attached to X and
|
||||
Y. From now on, the propagator will be invoked whenever the domains of
|
||||
X or Y are changed. Then, clpfd:trigger_once/1 is used to give the
|
||||
propagator its first chance for propagation even though the variables'
|
||||
domains have not yet changed. Finally, clpfd:run_propagator/2 is
|
||||
extended to define the actual propagator. As explained, this predicate
|
||||
is automatically called by the constraint solver. The first argument
|
||||
is the user-defined representation of the constraint as used in
|
||||
clpfd:make_propagator/2, and the second argument is a mutable state
|
||||
that can be used to prevent further invocations of the propagator when
|
||||
the constraint has become entailed, by using clpfd:kill/1. An example
|
||||
of using the new constraint:
|
||||
|
||||
==
|
||||
?- oneground(X, Y, Z), Y = 5.
|
||||
Y = 5,
|
||||
Z = 1,
|
||||
X in inf..sup.
|
||||
==
|
||||
|
||||
@author Markus Triska
|
||||
*/
|
||||
|
||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
A bound is either:
|
||||
|
||||
|
@ -2,11 +2,13 @@
|
||||
% SWI emulation.
|
||||
% written in an on-demand basis.
|
||||
|
||||
%% @defgroup SWILibrary Compatibility with SWI-Prolog and Other Prolog systems
|
||||
|
||||
/**
|
||||
|
||||
@defgroup System SWI Dialect Support
|
||||
|
||||
|
||||
This library provides a number of SWI-Prolog builtins that are not by
|
||||
default in YAP. This support is loaded with the
|
||||
~~~~~
|
||||
|
@ -5,6 +5,17 @@
|
||||
% Updated: 29 November 1983
|
||||
% Purpose: Implement heaps in Prolog.
|
||||
|
||||
:- module(heaps,[
|
||||
add_to_heap/4, % Heap x Key x Datum -> Heap
|
||||
get_from_heap/4, % Heap -> Key x Datum x Heap
|
||||
empty_heap/1, % Heap
|
||||
heap_size/2, % Heap -> Size
|
||||
heap_to_list/2, % Heap -> List
|
||||
list_to_heap/2, % List -> Heap
|
||||
min_of_heap/3, % Heap -> Key x Datum
|
||||
min_of_heap/5 % Heap -> (Key x Datum) x (Key x Datum)
|
||||
]).
|
||||
|
||||
|
||||
/** @defgroup Heaps Heaps
|
||||
@ingroup YAPLibrary
|
||||
@ -129,16 +140,6 @@ the pair with the smallest Key), but does not remove it from the heap.
|
||||
|
||||
|
||||
*/
|
||||
:- module(heaps,[
|
||||
add_to_heap/4, % Heap x Key x Datum -> Heap
|
||||
get_from_heap/4, % Heap -> Key x Datum x Heap
|
||||
empty_heap/1, % Heap
|
||||
heap_size/2, % Heap -> Size
|
||||
heap_to_list/2, % Heap -> List
|
||||
list_to_heap/2, % List -> Heap
|
||||
min_of_heap/3, % Heap -> Key x Datum
|
||||
min_of_heap/5 % Heap -> (Key x Datum) x (Key x Datum)
|
||||
]).
|
||||
|
||||
/*
|
||||
:- mode
|
||||
@ -160,7 +161,8 @@ the pair with the smallest Key), but does not remove it from the heap.
|
||||
*/
|
||||
|
||||
|
||||
% add_to_heap(OldHeap, Key, Datum, NewHeap)
|
||||
%% @pred add_to_heap(OldHeap, Key, Datum, NewHeap)
|
||||
%
|
||||
% inserts the new Key-Datum pair into the heap. The insertion is
|
||||
% not stable, that is, if you insert several pairs with the same
|
||||
% Key it is not defined which of them will come out first, and it
|
||||
@ -204,7 +206,8 @@ sort2(Key1, Datum1, Key2, Datum2, Key2, Datum2, Key1, Datum1).
|
||||
|
||||
|
||||
|
||||
% get_from_heap(OldHeap, Key, Datum, NewHeap)
|
||||
%% @pred get_from_heap(OldHeap, Key, Datum, NewHeap)
|
||||
%
|
||||
% returns the Key-Datum pair in OldHeap with the smallest Key, and
|
||||
% also a New Heap which is the Old Heap with that pair deleted.
|
||||
% The easy part is picking off the smallest element. The hard part
|
||||
@ -236,14 +239,16 @@ repair_heap(t, t, t, 1) :- !.
|
||||
|
||||
|
||||
|
||||
% heap_size(Heap, Size)
|
||||
%% @pred heap_size(Heap, Size)
|
||||
%
|
||||
% reports the number of elements currently in the heap.
|
||||
|
||||
heap_size(t(Size,_,_), Size).
|
||||
|
||||
|
||||
|
||||
% heap_to_list(Heap, List)
|
||||
%% @pred heap_to_list(Heap, List)
|
||||
%
|
||||
% returns the current set of Key-Datum pairs in the Heap as a
|
||||
% List, sorted into ascending order of Keys. This is included
|
||||
% simply because I think every data structure foo ought to have
|
||||
@ -275,7 +280,8 @@ heap_tree_to_list(T, [], T).
|
||||
|
||||
|
||||
|
||||
% list_to_heap(List, Heap)
|
||||
%% @pred list_to_heap(List, Heap)
|
||||
%
|
||||
% takes a list of Key-Datum pairs (such as keysort could be used to
|
||||
% sort) and forms them into a heap. We could do that a wee bit
|
||||
% faster by keysorting the list and building the tree directly, but
|
||||
@ -295,12 +301,14 @@ list_to_heap([Key-Datum|Rest], M, OldTree, Heap) :-
|
||||
|
||||
|
||||
|
||||
% min_of_heap(Heap, Key, Datum)
|
||||
%% @pred min_of_heap(Heap, Key, Datum)
|
||||
%
|
||||
% returns the Key-Datum pair at the top of the heap (which is of
|
||||
% course the pair with the smallest Key), but does not remove it
|
||||
% from the heap. It fails if the heap is empty.
|
||||
|
||||
% min_of_heap(Heap, Key1, Datum1, Key2, Datum2)
|
||||
%% @pred min_of_heap(Heap, Key1, Datum1, Key2, Datum2)
|
||||
%
|
||||
% returns the smallest (Key1) and second smallest (Key2) pairs in
|
||||
% the heap, without deleting them. It fails if the heap does not
|
||||
% have at least two elements.
|
||||
|
@ -46,21 +46,23 @@ official policies, either expressed or implied, of Ulrich Neumerkel.
|
||||
This library provides lambda expressions to simplify higher order
|
||||
programming based on call/N.
|
||||
|
||||
Lambda expressions are represented by ordinary Prolog terms.
|
||||
There are two kinds of lambda expressions:
|
||||
Lambda expressions are represented by ordinary Prolog terms.
|
||||
There are two kinds of lambda expressions:
|
||||
|
||||
Free+\X1^X2^ ..^XN^Goal
|
||||
~~~~
|
||||
Free+\X1^X2^ ..^XN^Goal
|
||||
|
||||
\X1^X2^ ..^XN^Goal
|
||||
~~~~
|
||||
|
||||
The second is a shorthand for t+\X1^X2^..^XN^Goal.
|
||||
The second is a shorthand for t+\X1^X2^..^XN^Goal
|
||||
|
||||
Xi are the parameters.
|
||||
+ _Xi_ are the parameters.
|
||||
|
||||
Goal is a goal or continuation. Syntax note: Operators within Goal
|
||||
+ _Goal_ is a goal or continuation. Syntax note: Operators within Goal
|
||||
require parentheses due to the low precedence of the ^ operator.
|
||||
|
||||
Free contains variables that are valid outside the scope of the lambda
|
||||
+ _Free_ contains variables that are valid outside the scope of the lambda
|
||||
expression. They are thus free variables within.
|
||||
|
||||
All other variables of Goal are considered local variables. They must
|
||||
@ -69,20 +71,20 @@ currently not checked. Violations may lead to unexpected bindings.
|
||||
|
||||
In the following example the parentheses around X>3 are necessary.
|
||||
|
||||
==
|
||||
~~~~~
|
||||
?- use_module(library(lambda)).
|
||||
?- use_module(library(apply)).
|
||||
|
||||
?- maplist(\X^(X>3),[4,5,9]).
|
||||
true.
|
||||
==
|
||||
~~~~~
|
||||
|
||||
In the following X is a variable that is shared by both instances of
|
||||
In the following _X_ is a variable that is shared by both instances of
|
||||
the lambda expression. The second query illustrates the cooperation of
|
||||
continuations and lambdas. The lambda expression is in this case a
|
||||
continuation expecting a further argument.
|
||||
|
||||
==
|
||||
~~~~~
|
||||
?- Xs = [A,B], maplist(X+\Y^dif(X,Y), Xs).
|
||||
Xs = [A, B],
|
||||
dif(X, A),
|
||||
@ -92,11 +94,11 @@ dif(X, B).
|
||||
Xs = [A, B],
|
||||
dif(X, A),
|
||||
dif(X, B).
|
||||
==
|
||||
~~~~~
|
||||
|
||||
The following queries are all equivalent. To see this, use
|
||||
the fact f(x,y).
|
||||
==
|
||||
~~~~~
|
||||
?- call(f,A1,A2).
|
||||
?- call(\X^f(X),A1,A2).
|
||||
?- call(\X^Y^f(X,Y), A1,A2).
|
||||
@ -106,7 +108,7 @@ the fact f(x,y).
|
||||
?- f(A1,A2).
|
||||
A1 = x,
|
||||
A2 = y.
|
||||
==
|
||||
~~~~~
|
||||
|
||||
Further discussions
|
||||
http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/ISO-Hiord
|
||||
|
@ -1,3 +1,10 @@
|
||||
/**
|
||||
|
||||
@defgroup YAPControl Meta- and Control Predicates
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
% Also has code from:
|
||||
% File : APPLIC.PL
|
||||
% Author : Lawrence Byrd + Richard A. O'Keefe
|
||||
@ -34,13 +41,13 @@
|
||||
* @author E. Alphonse
|
||||
* @author Vitor Santos Costa
|
||||
|
||||
|
||||
|
||||
Examples:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
|
||||
%given
|
||||
plus(X,Y,Z) :- Z is X + Y.
|
||||
|
||||
|
||||
plus_if_pos(X,Y,Z) :- Y > 0, Z is X + Y.
|
||||
|
||||
vars(X, Y, [X|Y]) :- var(X), !.
|
||||
@ -68,9 +75,43 @@ trans(X,X).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@{
|
||||
|
||||
|
||||
*/
|
||||
|
||||
:- module(maplist,
|
||||
[maplist/2,
|
||||
maplist/3,
|
||||
maplist/4,
|
||||
maplist/5,
|
||||
checklist/2,
|
||||
checknodes/2,
|
||||
convlist/3,
|
||||
foldl/4,
|
||||
foldl/5,
|
||||
foldl/6,
|
||||
foldl/7,
|
||||
foldl2/6,
|
||||
foldl2/7,
|
||||
foldl2/8,
|
||||
foldl3/8,
|
||||
foldl4/10,
|
||||
include/3,
|
||||
exclude/3,
|
||||
mapnodes/3,
|
||||
partition/4,
|
||||
partition/5,
|
||||
scanl/4,
|
||||
scanl/5,
|
||||
scanl/6,
|
||||
scanl/7,
|
||||
selectlist/3,
|
||||
selectlist/4,
|
||||
selectlists/5,
|
||||
sumlist/4,
|
||||
sumnodes/4
|
||||
]).
|
||||
|
||||
|
||||
|
||||
/** @pred maplist(+ _Pred_,+ _List1_,+ _List2_)
|
||||
|
||||
@ -79,7 +120,7 @@ Apply _Pred_ on all successive pairs of elements from
|
||||
_List2_. Fails if _Pred_ can not be applied to a
|
||||
pair. See the example above.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred maplist(+ _Pred_,+ _List1_,+ _List2_,+ _List4_)
|
||||
|
||||
@ -87,43 +128,7 @@ Apply _Pred_ on all successive triples of elements from _List1_,
|
||||
_List2_ and _List3_. Fails if _Pred_ can not be applied to a
|
||||
triple. See the example above.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
:- module(maplist, [selectlist/3,
|
||||
selectlist/4,
|
||||
selectlists/5,
|
||||
checklist/2,
|
||||
maplist/2, % :Goal, +List
|
||||
maplist/3, % :Goal, ?List1, ?List2
|
||||
maplist/4, % :Goal, ?List1, ?List2, ?List
|
||||
maplist/5, % :Goal, ?List1, ?List2, ?List3, List4
|
||||
convlist/3,
|
||||
mapnodes/3,
|
||||
checknodes/2,
|
||||
sumlist/4,
|
||||
sumnodes/4,
|
||||
include/3,
|
||||
exclude/3,
|
||||
partition/4,
|
||||
partition/5,
|
||||
foldl/4, % :Pred, +List, ?V0, ?V
|
||||
foldl2/6, % :Pred, +List, ?V0, ?V, ?W0, ?W
|
||||
foldl2/7, % :Pred, +List1, ?List2, ?V0, ?V, ?W0, ?W
|
||||
foldl2/8, % :Pred, +List1, ?List2, ?List3, ?V0, ?V, ?W0, ?W
|
||||
foldl3/8, % :Pred, +List, ?V0, ?V, ?W0, ?W
|
||||
foldl4/10, % :Pred, +List, ?V0, ?V, ?W0, ?W, ...
|
||||
foldl/5, % :Pred, +List1, +List2, ?V0, ?V
|
||||
foldl/6, % :Pred, +List1, +List2, +List3, ?V0, ?V
|
||||
foldl/7, % :Pred, +List1, +List2, +List3, +List4,
|
||||
% ?V0, ?V
|
||||
scanl/4, % :Pred, +List, ?V0, ?Vs
|
||||
scanl/5, % :Pred, +List1, +List2, ?V0, ?Vs
|
||||
scanl/6, % :Pred, +List1, +List2, +List3, ?V0, ?Vs
|
||||
scanl/7 % :Pred, +List1, +List2, +List3, +List4,
|
||||
]).
|
||||
|
||||
|
||||
:- meta_predicate
|
||||
selectlist(2,+,-),
|
||||
@ -158,7 +163,7 @@ triple. See the example above.
|
||||
scanl(4, +, +, +, -),
|
||||
scanl(5, +, +, +, +, -),
|
||||
scanl(6, +, +, +, +, +, -).
|
||||
|
||||
|
||||
:- use_module(library(maputils)).
|
||||
:- use_module(library(lists), [append/3]).
|
||||
:- use_module(library(charsio), [format_to_chars/3, read_from_chars/2]).
|
||||
@ -176,7 +181,7 @@ triple. See the example above.
|
||||
*/
|
||||
include(G,In,Out) :-
|
||||
selectlist(G, In, Out).
|
||||
|
||||
|
||||
/** selectlist(: _Pred_, + _ListIn_, ? _ListOut_))
|
||||
Creates _ListOut_ of all list elements of _ListIn_ that pass a given test
|
||||
*/
|
||||
@ -304,7 +309,7 @@ maplist(Pred, [In|ListIn]) :-
|
||||
corresponding element in lists _L1_, _L2_.
|
||||
|
||||
Comment from Richard O'Keefe: succeeds when _Pred( _Old_, _New_) succeeds for each corresponding
|
||||
_Gi_ in _Listi_, _New_ in _NewList_. In InterLisp, this is MAPCAR.
|
||||
_Gi_ in _Listi_, _New_ in _NewList_. In InterLisp, this is MAPCAR.
|
||||
It is also MAP2C. Isn't bidirectionality wonderful?
|
||||
*/
|
||||
maplist(_, [], []).
|
||||
@ -360,9 +365,9 @@ convlist(Pred, [_|Olds], News) :-
|
||||
|
||||
/**
|
||||
mapnodes(+ _Pred_, + _TermIn_, ? _TermOut_)
|
||||
|
||||
|
||||
Creates _TermOut_ by applying the predicate _Pred_
|
||||
to all sub-terms of _TermIn_ (depth-first and left-to-right order).
|
||||
to all sub-terms of _TermIn_ (depth-first and left-to-right order).
|
||||
*/
|
||||
mapnodes(Pred, TermIn, TermOut) :-
|
||||
(atomic(TermIn); var(TermIn)), !,
|
||||
@ -462,7 +467,7 @@ foldl_([H|T], Goal, V0, V) :-
|
||||
_List2_ and collects a result in _Accumulator_. Same as
|
||||
foldr/4.
|
||||
|
||||
The foldl family of predicates is defined
|
||||
The foldl family of predicates is defined
|
||||
==
|
||||
foldl(P, [X11,...,X1n],V0, Vn, W0, WN) :-
|
||||
P(X11, V0, V1, W0, W1),
|
||||
@ -479,7 +484,7 @@ foldl_([H1|T1], [H2|T2], Goal, V0, V) :-
|
||||
foldl_(T1, T2, Goal, V1, V).
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
foldl(Goal, List1, List2, List3, V0, V) :-
|
||||
foldl_(List1, List2, List3, Goal, V0, V).
|
||||
@ -491,7 +496,7 @@ foldl_([H1|T1], [H2|T2], [H3|T3], Goal, V0, V) :-
|
||||
|
||||
|
||||
/**
|
||||
|
||||
|
||||
*/
|
||||
foldl(Goal, List1, List2, List3, List4, V0, V) :-
|
||||
foldl_(List1, List2, List3, List4, Goal, V0, V).
|
||||
@ -504,7 +509,7 @@ foldl_([H1|T1], [H2|T2], [H3|T3], [H4|T4], Goal, V0, V) :-
|
||||
|
||||
/**
|
||||
foldl2(: _Pred_, + _List_, ? _X0_, ? _X_, ? _Y0_, ? _Y_)
|
||||
|
||||
|
||||
Calls _Pred_ on all elements of `List` and collects a result in
|
||||
_X_ and _Y_.
|
||||
|
||||
@ -623,7 +628,7 @@ scanl_([H|T], Goal, V, [VH|VT]) :-
|
||||
/**
|
||||
scanl(: _Pred_, + _List1_, + _List2_, ? _V0_, ? _Vs_)
|
||||
|
||||
Left scan of list.
|
||||
Left scan of list.
|
||||
*/
|
||||
scanl(Goal, List1, List2, V0, [V0|Values]) :-
|
||||
scanl_(List1, List2, Goal, V0, Values).
|
||||
@ -636,7 +641,7 @@ scanl_([H1|T1], [H2|T2], Goal, V, [VH|VT]) :-
|
||||
/**
|
||||
scanl(: _Pred_, + _List1_, + _List2_, + _List3_, ? _V0_, ? _Vs_)
|
||||
|
||||
Left scan of list.
|
||||
Left scan of list.
|
||||
*/
|
||||
scanl(Goal, List1, List2, List3, V0, [V0|Values]) :-
|
||||
scanl_(List1, List2, List3, Goal, V0, Values).
|
||||
@ -648,8 +653,8 @@ scanl_([H1|T1], [H2|T2], [H3|T3], Goal, V, [VH|VT]) :-
|
||||
|
||||
/**
|
||||
scanl(: _Pred_, + _List1_, + _List2_, + _List3_, + _List4_, ? _V0_, ? _Vs_)
|
||||
|
||||
Left scan of list.
|
||||
|
||||
Left scan of list.
|
||||
*/
|
||||
scanl(Goal, List1, List2, List3, List4, V0, [V0|Values]) :-
|
||||
scanl_(List1, List2, List3, List4, Goal, V0, Values).
|
||||
@ -685,7 +690,7 @@ goal_expansion(maplist(Meta, List), Mod:Goal) :-
|
||||
goal_expansion_allowed,
|
||||
callable(Meta),
|
||||
prolog_load_context(module, Mod),
|
||||
aux_preds(Meta, MetaVars, Pred, PredVars, Proto),
|
||||
aux_preds(Meta, MetaVars, Pred, PredVars, Proto),
|
||||
!,
|
||||
% the new goal
|
||||
pred_name(maplist, 2, Proto, GoalName),
|
||||
@ -705,7 +710,7 @@ goal_expansion(maplist(Meta, List), Mod:Goal) :-
|
||||
goal_expansion(maplist(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
goal_expansion_allowed,
|
||||
callable(Meta),
|
||||
prolog_load_context(module, Mod),
|
||||
prolog_load_context(module, Mod),
|
||||
aux_preds(Meta, MetaVars, Pred, PredVars, Proto),
|
||||
!,
|
||||
% the new goal
|
||||
@ -713,7 +718,7 @@ goal_expansion(maplist(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], [Out|Outs]], RecursionHead),
|
||||
append_args(Pred, [In, Out], Apply),
|
||||
@ -734,7 +739,7 @@ goal_expansion(maplist(Meta, L1, L2, L3), Mod:Goal) :-
|
||||
append(MetaVars, [L1, L2, L3], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], []], Base),
|
||||
append_args(HeadPrefix, [[A1|A1s], [A2|A2s], [A3|A3s]], RecursionHead),
|
||||
append_args(Pred, [A1, A2, A3], Apply),
|
||||
@ -755,7 +760,7 @@ goal_expansion(maplist(Meta, L1, L2, L3, L4), Mod:Goal) :-
|
||||
append(MetaVars, [L1, L2, L3, L4], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], [], []], Base),
|
||||
append_args(HeadPrefix, [[A1|A1s], [A2|A2s], [A3|A3s], [A4|A4s]], RecursionHead),
|
||||
append_args(Pred, [A1, A2, A3, A4], Apply),
|
||||
@ -776,7 +781,7 @@ goal_expansion(selectlist(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs], RecursionHead),
|
||||
append_args(Pred, [In], Apply),
|
||||
@ -799,7 +804,7 @@ goal_expansion(selectlist(Meta, ListIn, ListIn1, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListIn1, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], [In1|Ins1], Outs], RecursionHead),
|
||||
append_args(Pred, [In, In1], Apply),
|
||||
@ -822,7 +827,7 @@ goal_expansion(selectlists(Meta, ListIn, ListIn1, ListOut, ListOut1), Mod:Goal)
|
||||
append(MetaVars, [ListIn, ListIn1, ListOut, ListOut1], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], [], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], [In1|Ins1], Outs, Outs1], RecursionHead),
|
||||
append_args(Pred, [In, In1], Apply),
|
||||
@ -846,7 +851,7 @@ goal_expansion(include(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs], RecursionHead),
|
||||
append_args(Pred, [In], Apply),
|
||||
@ -869,7 +874,7 @@ goal_expansion(exclude(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs], RecursionHead),
|
||||
append_args(Pred, [In], Apply),
|
||||
@ -892,7 +897,7 @@ goal_expansion(partition(Meta, ListIn, List1, List2), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, List1, List2], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs1, Outs2], RecursionHead),
|
||||
append_args(Pred, [In], Apply),
|
||||
@ -915,7 +920,7 @@ goal_expansion(partition(Meta, ListIn, List1, List2, List3), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, List1, List2, List3], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], [], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs1, Outs2, Outs3], RecursionHead),
|
||||
append_args(Pred, [In,Diff], Apply),
|
||||
@ -955,7 +960,7 @@ goal_expansion(convlist(Meta, ListIn, ListOut), Mod:Goal) :-
|
||||
append(MetaVars, [ListIn, ListOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], []], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Outs], RecursionHead),
|
||||
append_args(Pred, [In, Out], Apply),
|
||||
@ -978,7 +983,7 @@ goal_expansion(sumlist(Meta, List, AccIn, AccOut), Mod:Goal) :-
|
||||
append(MetaVars, [List, AccIn, AccOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3], Apply),
|
||||
@ -999,7 +1004,7 @@ goal_expansion(foldl(Meta, List, AccIn, AccOut), Mod:Goal) :-
|
||||
append(MetaVars, [List, AccIn, AccOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3], Apply),
|
||||
@ -1020,7 +1025,7 @@ goal_expansion(foldl(Meta, List1, List2, AccIn, AccOut), Mod:Goal) :-
|
||||
append(MetaVars, [List1, List2, AccIn, AccOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], Acc, Acc], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], [I2|Is2], Acc1, Acc2], RecursionHead),
|
||||
append_args(Pred, [In, I2, Acc1, Acc3], Apply),
|
||||
@ -1041,7 +1046,7 @@ goal_expansion(foldl(Meta, List1, List2, List3, AccIn, AccOut), Mod:Goal) :-
|
||||
append(MetaVars, [List1, List2, List3, AccIn, AccOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], [], Acc, Acc], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], [I2|I2s], [I3|I3s], Acc1, Acc2], RecursionHead),
|
||||
append_args(Pred, [In, I2, I3, Acc1, Acc3], Apply),
|
||||
@ -1062,7 +1067,7 @@ goal_expansion(foldl2(Meta, List, AccIn, AccOut, W0, W), Mod:Goal) :-
|
||||
append(MetaVars, [List, AccIn, AccOut, W0, W], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc, W, W], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2, W1, W2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3, W1, W3], Apply),
|
||||
@ -1083,7 +1088,7 @@ goal_expansion(foldl2(Meta, List1, List2, AccIn, AccOut, W0, W), Mod:Goal) :-
|
||||
append(MetaVars, [List1, List2, AccIn, AccOut, W0, W], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], Acc, Acc, W, W], Base),
|
||||
append_args(HeadPrefix, [[In1|Ins1], [In2|Ins2], Acc1, Acc2, W1, W2], RecursionHead),
|
||||
append_args(Pred, [In1, In2, Acc1, Acc3, W1, W3], Apply),
|
||||
@ -1104,7 +1109,7 @@ goal_expansion(foldl2(Meta, List1, List2, List3, AccIn, AccOut, W0, W), Mod:Goal
|
||||
append(MetaVars, [List1, List2, List3, AccIn, AccOut, W0, W], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], [], [], Acc, Acc, W, W], Base),
|
||||
append_args(HeadPrefix, [[In1|Ins1], [In2|Ins2], [In3|Ins3], Acc1, Acc2, W1, W2], RecursionHead),
|
||||
append_args(Pred, [In1, In2, In3, Acc1, Acc3, W1, W3], Apply),
|
||||
@ -1125,7 +1130,7 @@ goal_expansion(foldl3(Meta, List, AccIn, AccOut, W0, W, X0, X), Mod:Goal) :-
|
||||
append(MetaVars, [List, AccIn, AccOut, W0, W, X0, X], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc, W, W, X, X], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2, W1, W2, X1, X2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3, W1, W3, X1, X3], Apply),
|
||||
@ -1146,7 +1151,7 @@ goal_expansion(foldl4(Meta, List, AccIn, AccOut, W0, W, X0, X, Y0, Y), Mod:Goal)
|
||||
append(MetaVars, [List, AccIn, AccOut, W0, W, X0, X, Y0, Y], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc, W, W, X, X, Y, Y], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2, W1, W2, X1, X2, Y1, Y2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3, W1, W3, X1, X3, Y1, Y3], Apply),
|
||||
@ -1229,7 +1234,7 @@ goal_expansion(sumnodes(Meta, Term, AccIn, AccOut), Mod:Goal) :-
|
||||
append(MetaVars, [[Term], AccIn, AccOut], GoalArgs),
|
||||
Goal =.. [GoalName|GoalArgs],
|
||||
% the new predicate declaration
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
HeadPrefix =.. [GoalName|PredVars],
|
||||
append_args(HeadPrefix, [[], Acc, Acc], Base),
|
||||
append_args(HeadPrefix, [[In|Ins], Acc1, Acc2], RecursionHead),
|
||||
append_args(Pred, [In, Acc1, Acc3], Apply),
|
||||
@ -1251,4 +1256,3 @@ goal_expansion(sumnodes(Meta, Term, AccIn, AccOut), Mod:Goal) :-
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
|
@ -14,7 +14,7 @@ from sockets. The following calls are available:
|
||||
|
||||
|
||||
@tbd Our implementation does not support AF_UNIX sockets.
|
||||
@TBD Implement socket_select/5
|
||||
@tbd Implement socket_select/5
|
||||
@see http://www.sics.se/sicstus/docs/3.7.1/html/sicstus_28.html
|
||||
*/
|
||||
|
||||
|
126
misc/sysgraph
Normal file → Executable file
126
misc/sysgraph
Normal file → Executable file
@ -1,3 +1,6 @@
|
||||
#!/usr/local/bin/yap -L -- *
|
||||
#.
|
||||
|
||||
|
||||
:- style_check(all).
|
||||
|
||||
@ -28,7 +31,8 @@
|
||||
library/1,
|
||||
undef/2,
|
||||
c_dep/2,
|
||||
do_comment/5.
|
||||
do_comment/5,
|
||||
module_file/2.
|
||||
|
||||
% @short node(?Module:module, ?Predicate:pred_indicator, ?File:file, ?Generator:atom) is nondet
|
||||
%
|
||||
@ -133,6 +137,9 @@ init :-
|
||||
user_expand(N,A),
|
||||
do_user_expand(N,A),
|
||||
fail.
|
||||
init :-
|
||||
catch( make_directory(tmp), _, fail),
|
||||
fail.
|
||||
init.
|
||||
|
||||
init_loop( _Dirs ).
|
||||
@ -188,7 +195,7 @@ c_file(F, Mod) :-
|
||||
c_ext(S, Mod, F),
|
||||
fail
|
||||
;
|
||||
split_string(String, ",; ()\t\"\'", Fields),
|
||||
split_string(String, ",; ()\t\"\'", Fields), %'
|
||||
%writeln(Fields),
|
||||
line_count(S, Lines),
|
||||
c_line(Fields , Mod, F:Lines),
|
||||
@ -213,7 +220,7 @@ c_ext( S, Mod, F ) :-
|
||||
sub_string( String, _, _, _, "NULL" ),
|
||||
!
|
||||
;
|
||||
split_string(String, ",; (){}\t\"\'", ["FRG", NS,AS,FS|_]),
|
||||
split_string(String, ",; (){}\t\"\'", ["FRG", NS,AS,FS|_]), %'
|
||||
atom_string(N,NS),
|
||||
atom_string(Fu,FS),
|
||||
number_string(A, AS),
|
||||
@ -222,7 +229,7 @@ c_ext( S, Mod, F ) :-
|
||||
assert( node( Mod , N/A, F-Line, Fu ) ),
|
||||
handle_pred( Mod, N, A, F )
|
||||
;
|
||||
split_string(String, ",; (){}\t\"\'", [NS,AS,FS|_]),
|
||||
split_string(String, ",; (){}\t\"\'", [NS,AS,FS|_]), %'
|
||||
atom_string(N,NS),
|
||||
atom_string(Fu,FS),
|
||||
number_string(A, AS),
|
||||
@ -453,6 +460,7 @@ get_interf( (:- V ), _F, _M ) :-
|
||||
!.
|
||||
get_interf( (:- module( NM, Is ) ), F, _M ) :-
|
||||
!,
|
||||
assert(module_file( F, NM ) ),
|
||||
nb_setval( current_module, NM ),
|
||||
assert( module_on( F , NM, Is) ),
|
||||
maplist( public(F, NM), Is ),
|
||||
@ -648,14 +656,22 @@ exported( NF, F, NM, M, op(X,Y,Z)) :-
|
||||
public( NF , NM:op(X,Y,Z) ),
|
||||
handle_op( F, M , op(X,Y,Z) ).
|
||||
exported( NF, F, NM, M, N/A) :- !,
|
||||
% sink no more
|
||||
retractall( exported(( _ :- F-M:N/A) ) ),
|
||||
assert_new( exported( (F-M:N/A :- NF-NM:N/A )) ).
|
||||
exported( NF, F, NM, M, N/A as NN) :- !,
|
||||
% sink no more
|
||||
retractall( exported(( _ :- F-M:N/A) ) ),
|
||||
assert_new( exported( ( F-M:NN/A :- NF-NM:N/A ) ) ).
|
||||
exported( NF, F, NM, M, N//A) :- !,
|
||||
A2 is A+2,
|
||||
% sink no more
|
||||
retractall( exported(( _ :- F-M:N/A2) ) ),
|
||||
assert_new( exported( (F-M:N/A2 :- NF-NM:N/A2) ) ).
|
||||
exported( NF, F, NM, M, N//A as NN) :- !,
|
||||
A2 is A+2,
|
||||
% sink no more
|
||||
retractall( exported(( _ :- F-M:N/A2) ) ),
|
||||
assert_new( exported( ( F-M:NN/A2 :- NF-NM:N/A2 )) ).
|
||||
|
||||
import_publics( F, ProducerMod, ConsumerMod ) :-
|
||||
@ -1036,16 +1052,29 @@ always_strip_module(M0:A, M0, call(A)) :- var(A),!.
|
||||
always_strip_module(M0:A, M0, A).
|
||||
|
||||
c_links :-
|
||||
open('foreigns.yap', write, S),
|
||||
open('tmp/foreigns.yap', write, S),
|
||||
clinks(S).
|
||||
|
||||
clinks(S) :-
|
||||
exported( ( _-M:F/A :- _-M1:F1/A ) ),
|
||||
format( S, ':- export( ~a:~a/~d , ~a:~a/~d ).~n', [M,F,A , M1,F1,A] ),
|
||||
module_file( F, NM ),
|
||||
format( S, 'mod( ~q , ~q ). ~n', [NM, F] ),
|
||||
fail.
|
||||
clinks(S) :-
|
||||
exported( ( Fi0-M:F/A :- Fi1-M1:F1/A ) ),
|
||||
( M \= M1 -> M \= prolog ; F \= F1 ),
|
||||
functor(S0, F, A),
|
||||
S0 =.. [F| Args],
|
||||
S1 =.. [F1| Args],
|
||||
numbervars(Args, 0, _),
|
||||
format( S, '% ~q <- ~q.~n~q:~q :- ~q:~q. ~n', [Fi0, Fi1, M,S0, M1,S1] ),
|
||||
fail.
|
||||
clinks(S) :-
|
||||
node( M, P, File-Line, c(F)),
|
||||
format( S, ':- foreign_predicate( ~q , ~q , ~q , ~d ).~n', [M:P, F, File, Line] ),
|
||||
node( M, F/A, File-Line, c(F)),
|
||||
functor( S0, F, A),
|
||||
S0 =.. [F| Args],
|
||||
S1 =.. [foreign, F| Args],
|
||||
numbervars(Args, 0, _),
|
||||
format( S, ' ~a:~d~nforeign(~q , ~q , ~q, ~q ).~n', [File, Line, M:S0, S1, File, Line] ),
|
||||
fail.
|
||||
clinks(S) :-
|
||||
close(S).
|
||||
@ -1060,7 +1089,8 @@ warn_singletons(_Vars, _Pos).
|
||||
comment( _Pos - Comment) :-
|
||||
skip_blanks(1, Comment, N),
|
||||
doc( Comment, N ), !,
|
||||
format( "%s\n", [Comment] ).
|
||||
format( "%s\n", [Comment] ),
|
||||
verif
|
||||
comment( _Pos - _Comment).
|
||||
|
||||
skip_blanks(I, Comment, N) :-
|
||||
@ -1073,7 +1103,7 @@ skip_blanks(N, _Comment, N).
|
||||
doc( Comment , N ) :-
|
||||
N1 is N+1,
|
||||
sub_string( Comment, N1, 3, _, Header ),
|
||||
( Header == "/**" -> true ; Header == "/*!" ), !,
|
||||
( Header == "/**" -> true ; Header == "/*!" ), !, % */
|
||||
N4 is N+4,
|
||||
get_string_code( N4, Comment, Code ),
|
||||
code_type( Code, space ).
|
||||
@ -1291,11 +1321,11 @@ error( Error ) :- throw(Error ).
|
||||
%
|
||||
%
|
||||
mkdocs :-
|
||||
open( pages, write, S1),
|
||||
open( 'tmp/pages', write, S1),
|
||||
close( S1 ),
|
||||
open( bads, write, S2),
|
||||
open( 'tmp/bads', write, S2),
|
||||
close( S2 ),
|
||||
open( groups, write, S3),
|
||||
open( 'tmp/groups', write, S3),
|
||||
close( S3 ),
|
||||
open( 'docs/yapdocs.yap', read, S),
|
||||
repeat,
|
||||
@ -1315,7 +1345,7 @@ blanks( S , T, TF) :-
|
||||
read_line_to_codes(S, T1, T2),
|
||||
( T1 == end_of_file -> fail;
|
||||
T2 == [] -> fail;
|
||||
T1 \== T2, foldl( check, [0'/,0'*,0'*],T1, _) -> TF = T2, T = T1 ;
|
||||
T1 \== T2, foldl( check, [0'/,0'*,0'*],T1, _) -> TF = T2, T = T1 ; % '
|
||||
blanks( S , T, TF) ).
|
||||
|
||||
get_comment( S , T) :-
|
||||
@ -1329,7 +1359,7 @@ check(C, [C0|L], L) :-
|
||||
C == C0.
|
||||
|
||||
diff_end( L, T, [] ) :-
|
||||
append(_, L, T).
|
||||
append(_, L, T).
|
||||
|
||||
store_comment(Comment) :-
|
||||
header( Pred, A, Comment, _ ),
|
||||
@ -1338,7 +1368,9 @@ store_comment(Comment) :-
|
||||
true
|
||||
;
|
||||
format('Missing definition for ~q.~n', [P/A] ),
|
||||
( node( Mod, P/Ar, File-Line, Type), format(' ~w exists.~n',[Mod:P/Ar]), fail )
|
||||
node( Mod, P/Ar, File-Line, Type),
|
||||
format(' ~w exists.~n',[Mod:P/Ar]),
|
||||
fail
|
||||
),
|
||||
( node( M1, P/A, _, _), M1 \= Mod -> Dup = true ; Dup = false),
|
||||
!,
|
||||
@ -1346,46 +1378,46 @@ store_comment(Comment) :-
|
||||
assert( do_comment( File, Line, C, Type, Dup ) ).
|
||||
store_comment(Comment) :-
|
||||
page( Comment, _ ), !,
|
||||
open( pages, append, S),
|
||||
open( 'tmp/pages', append, S),
|
||||
format(S, '*******************************~n~n~s~n~n', [Comment]),
|
||||
close(S).
|
||||
store_comment(Comment) :-
|
||||
defgroup( Comment, _ ), !,
|
||||
open( groups, append, S),
|
||||
open( 'tmp/groups', append, S),
|
||||
format(S, '*******************************~n~n~s~n~n', [Comment]),
|
||||
close(S).
|
||||
store_comment(Comment) :-
|
||||
open( bads, append, S),
|
||||
open( 'tmp/bads', append, S),
|
||||
format(S, '*******************************~n~n~s~n~n', [Comment]),
|
||||
close(S).
|
||||
|
||||
defgroup -->
|
||||
"/**",
|
||||
blank,
|
||||
"/**", % */
|
||||
blanks,
|
||||
"@defgroup".
|
||||
|
||||
page -->
|
||||
"/**",
|
||||
blank,
|
||||
"/**", % */
|
||||
blanks,
|
||||
"@page".
|
||||
|
||||
header(Pred, Arity) -->
|
||||
"/**",
|
||||
blank,
|
||||
"/**", % */
|
||||
blanks,
|
||||
"@pred",
|
||||
blank,
|
||||
blanks,
|
||||
atom(_),
|
||||
":",
|
||||
":",
|
||||
!,
|
||||
atom(Pred),
|
||||
atom_pred(Arity).
|
||||
header(Pred, Arity) -->
|
||||
"/**",
|
||||
blank,
|
||||
"/**", % */
|
||||
blanks,
|
||||
"@pred",
|
||||
blank,
|
||||
blanks,
|
||||
atom(Pred),
|
||||
atom_pred(Arity),
|
||||
atom_pred(Arity),
|
||||
!.
|
||||
header(Pred, 2, Comment, _) :-
|
||||
split(Comment, [[0'/,0'*,0'*],[0'@,0'p,0'r,0'e,0'd],_,Pred,_,[0'i,0's]|_]), !.
|
||||
@ -1440,6 +1472,7 @@ atom2([A|As]) -->
|
||||
atom2([]) --> [].
|
||||
|
||||
add_comments :-
|
||||
open('tmp/comments.yap', write, S),
|
||||
findall(File, do_comment( File, Line, C, Type, Dup), Fs0 ),
|
||||
(
|
||||
sort(Fs0, Fs),
|
||||
@ -1447,9 +1480,10 @@ add_comments :-
|
||||
setof(Line-C-Type-Dup, do_comment( File, Line, C, Type, Dup) , Lines0 ),
|
||||
reverse( Lines0, Lines),
|
||||
member(Line-Comment-Type-Dup, Lines),
|
||||
check_comment( Comment, CN, Line, File ),
|
||||
check_comment( Comment, CN, Line, File ),
|
||||
Line1 is Line-1,
|
||||
format(S, '#~a~ncat << "EOF" > tmp~n~sEOF~nsed -e "~dr tmp" ~a > x~n mv x ~a~n~n',[Dup,CN, Line1, File, File])
|
||||
format(S, '#~a~ncat << "EOF" > tmp~n~sEOF~nsed -e "~dr tmp" ~a > x~n\
|
||||
mv x ~a~n~n',[Dup,CN, Line1, File, File])
|
||||
;
|
||||
close(S)
|
||||
),
|
||||
@ -1457,11 +1491,13 @@ add_comments :-
|
||||
add_comments :-
|
||||
listing( open_comment ).
|
||||
|
||||
check_comment( Comment, CN, _Line, _File ) :-
|
||||
string_codes( Comment, C),
|
||||
check_comment( Comment, CN, _Line, File ) :-
|
||||
string_codes( Comment, [_,_,_|C]),
|
||||
check_groups(0,C,[]),
|
||||
check_quotes(0,C,[]),
|
||||
( append(C0,[0'@,0'},0' ,0'*,0'/,10], C) ->
|
||||
append(C0,[0'*,0'/,10], CN)
|
||||
(
|
||||
append(C0,[0'@,0'},0' ,0'*,0'/,10], C) -> %'
|
||||
append(C0,[0'*,0'/,10], CN)
|
||||
;
|
||||
CN = C
|
||||
),
|
||||
@ -1469,18 +1505,20 @@ check_comment( Comment, CN, _Line, _File ) :-
|
||||
check_comment( Comment, Comment, Line, File ) :-
|
||||
format(user_error,'*** bad comment ~a ~d~n~n~s~n~', [File,Line,Comment]).
|
||||
|
||||
check_groups(0,
|
||||
|
||||
check_quotes( 0 ) --> [].
|
||||
check_quotes( 0 ) -->
|
||||
check_quotes( 0 ) -->
|
||||
"`", !,
|
||||
check_quotes( 1 ).
|
||||
check_quotes( 1 ) -->
|
||||
check_quotes( 1 ) -->
|
||||
"`", !,
|
||||
check_quotes( 0 ).
|
||||
check_quotes( 1 ) -->
|
||||
check_quotes( 1 ) -->
|
||||
"\"", !, { fail }.
|
||||
check_quotes( 1 ) -->
|
||||
"'", !, { fail }.
|
||||
check_quotes( N ) -->
|
||||
check_quotes( 1 ) -->
|
||||
"'", !, { fail }. %'
|
||||
check_quotes( N ) -->
|
||||
[_],
|
||||
check_quotes( N ).
|
||||
|
||||
|
10
os/pl-file.c
10
os/pl-file.c
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup InputOutput
|
||||
/** @ingroup InputOutput
|
||||
@{
|
||||
|
||||
*/
|
||||
@ -4874,7 +4874,7 @@ PRED_IMPL("is_stream", 1, is_stream, 0)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup StreamM
|
||||
* @ingroup StreamM
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -4923,7 +4923,7 @@ PRED_IMPL("flush_output", 1, flush_output1, PL_FA_ISO)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup Stream
|
||||
* @ingroup Stream
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -5347,7 +5347,7 @@ peek(term_t stream, term_t chr, int how ARG_LD)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup CharsIO
|
||||
* @ingroup CharsIO
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -5452,7 +5452,7 @@ PRED_IMPL("peek_char", 1, peek_char1, 0)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup StreamM
|
||||
* @ingroup StreamM
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
27
pl/arith.yap
27
pl/arith.yap
@ -35,28 +35,26 @@
|
||||
/** @defgroup CompilerAnalysis Internal Clause Rewriting
|
||||
@ingroup YAPCompilerSettings
|
||||
|
||||
YAP supports several clause optimisation mechanisms, that
|
||||
are designed to improve execution of arithmetic
|
||||
and term construction built-ins. In other words, during the
|
||||
compilation process a clause is rewritten twice:
|
||||
YAP supports several clause optimisation mechanisms, that
|
||||
are designed to improve execution of arithmetic
|
||||
and term construction built-ins. In other words, during the
|
||||
compilation process a clause is rewritten twice:
|
||||
|
||||
1. first, perform user-defined goal_expansion as described
|
||||
in the predicates goal_expansion/1 and goal_expansion/2.
|
||||
1. first, perform user-defined goal_expansion as described
|
||||
in the predicates goal_expansion/1 and goal_expansion/2.
|
||||
|
||||
2. Perform expansion of some built-ins like:
|
||||
2. Perform expansion of some built-ins like:
|
||||
|
||||
+ pruning operators, like ->/2 and *->/2
|
||||
+ pruning operators, like ->/2 and *->/2
|
||||
|
||||
* arithmetic, including early evaluation of constant expressions
|
||||
+ arithmetic, including early evaluation of constant expressions
|
||||
|
||||
* specialise versions for some built-ins, if we are aware of the
|
||||
+ specialise versions for some built-ins, if we are aware of the
|
||||
run-time execution mode
|
||||
|
||||
The user has some control over this process, through some
|
||||
built-ins and through execution flsgs.
|
||||
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
/** @pred expand_exprs(- _O_,+ _N_)
|
||||
@ -112,7 +110,6 @@ q(A):-
|
||||
A is 22.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
*/
|
||||
do_not_compile_expressions :- set_value('$c_arith',[]).
|
||||
|
||||
@ -369,7 +366,5 @@ expand_expr(Op, X, Y, O, Q, P) :-
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@}
|
||||
|
||||
@}
|
||||
*/
|
||||
|
@ -4,7 +4,7 @@
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
@ -31,7 +31,7 @@
|
||||
:- use_system_module( '$_errors', ['$do_error'/2]).
|
||||
|
||||
|
||||
/** succ(? _Int1_:int, ? _Int2_:int) is det
|
||||
/** @pred succ(? _Int1_:int, ? _Int2_:int) is det
|
||||
*
|
||||
|
||||
True if _Int2_ = _Int1_ + 1 and _Int1_ \>= 0. At least
|
||||
@ -98,7 +98,7 @@ succ(M,N) :-
|
||||
N < 0,
|
||||
'$do_error'(domain_error(not_less_than_zero, N),succ(M,N)).
|
||||
|
||||
/** plus(? _Int1_:int, ? _Int2_:int, ? _Int3_:int) is det
|
||||
/** @pred plus(? _Int1_:int, ? _Int2_:int, ? _Int3_:int) is det
|
||||
|
||||
True if _Int3_ = _Int1_ + _Int2_. At least two of the
|
||||
three arguments must be instantiated to integers.
|
||||
|
113
pl/consult.yap
113
pl/consult.yap
@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
@ -66,7 +66,6 @@
|
||||
:- use_system_module( '$_preds', ['$current_predicate'/4]).
|
||||
|
||||
/**
|
||||
|
||||
\defgroup YAPConsulting Loading files into YAP
|
||||
@ingroup YAPLoading
|
||||
|
||||
@ -75,8 +74,9 @@ files and to set-up the Prolog environment. We discuss
|
||||
|
||||
+ @ref YAPReadFiles
|
||||
|
||||
+ @ref YAPCompilerSettings
|
||||
+ @ref YAPCompilerSettings
|
||||
|
||||
@{
|
||||
|
||||
@defgroup YAPReadFiles The Predicates that Read Source Files
|
||||
@ingroup YAPConsulting
|
||||
@ -814,14 +814,16 @@ db_files(Fs) :-
|
||||
G\='$'.
|
||||
|
||||
/**
|
||||
include(+ _F_) is directive
|
||||
|
||||
The `include` directive adds the text files or sequence of text
|
||||
files specified by _F_ into the files being currently consulted. It may be used
|
||||
as an replacement to consult/1 by allowing the programmer to include a data-base
|
||||
split into several files.
|
||||
@pred include(+ _F_) is directive
|
||||
|
||||
The `include` directive adds the text files or sequence of text
|
||||
files specified by _F_ into the files being currently consulted.
|
||||
It may be used
|
||||
as an replacement to consult/1 by allowing the programmer to include a
|
||||
data-base
|
||||
split into several files.
|
||||
*/
|
||||
|
||||
'$include'(V, _) :- var(V), !,
|
||||
'$do_error'(instantiation_error,include(V)).
|
||||
'$include'([], _) :- !.
|
||||
@ -901,60 +903,62 @@ source_file(Mod:Pred, FileName) :-
|
||||
|
||||
/** @pred prolog_load_context(? _Key_, ? _Value_)
|
||||
|
||||
Obtain information on what is going on in the compilation process. The
|
||||
following keys are available:
|
||||
|
||||
Obtain information on what is going on in the compilation process. The
|
||||
following keys are available:
|
||||
+ directory (prolog_load_context/2 option)
|
||||
|
||||
+ directory (prolog_load_context/2 option)
|
||||
Full name for the directory where YAP is currently consulting the
|
||||
file.
|
||||
|
||||
Full name for the directory where YAP is currently consulting the
|
||||
file.
|
||||
+ file (prolog_load_context/2 option)
|
||||
|
||||
+ file (prolog_load_context/2 option)
|
||||
Full name for the file currently being consulted. Notice that included
|
||||
filed are ignored.
|
||||
|
||||
Full name for the file currently being consulted. Notice that included
|
||||
filed are ignored.
|
||||
+ module (prolog_load_context/2 option)
|
||||
|
||||
+ module (prolog_load_context/2 option)
|
||||
Current source module.
|
||||
|
||||
Current source module.
|
||||
+ `source` (prolog_load_context/2 option)
|
||||
|
||||
+ `source` (prolog_load_context/2 option)
|
||||
Full name for the file currently being read in, which may be consulted,
|
||||
reconsulted, or included.
|
||||
|
||||
Full name for the file currently being read in, which may be consulted,
|
||||
reconsulted, or included.
|
||||
+ `stream` (prolog_load_context/2 option)
|
||||
|
||||
+ `stream` (prolog_load_context/2 option)
|
||||
Stream currently being read in.
|
||||
|
||||
Stream currently being read in.
|
||||
+ `term_position` (prolog_load_context/2 option)
|
||||
|
||||
+ `term_position` (prolog_load_context/2 option)
|
||||
Stream position at the stream currently being read in. For SWI
|
||||
compatibility, it is a term of the form
|
||||
'$stream_position'(0,Line,0,0).
|
||||
|
||||
Stream position at the stream currently being read in. For SWI
|
||||
compatibility, it is a term of the form
|
||||
'$stream_position'(0,Line,0,0).
|
||||
+ `source_location(? _File Name_, ? _Line_)` (prolog_load_context/2 option)
|
||||
|
||||
+ `source_location(? _FileName_, ? _Line_)` (prolog_load_context/2 option)
|
||||
SWI-compatible predicate. If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file. Please use prolog_load_context/2.
|
||||
|
||||
SWI-compatible predicate. If the last term has been read from a physical file (i.e., not from the file user or a string), unify File with an absolute path to the file and Line with the line-number in the file. Please use prolog_load_context/2.
|
||||
+ `source_file(? _File_)` (prolog_load_context/2 option)
|
||||
|
||||
+ `source_file(? _File_)` (prolog_load_context/2 option)
|
||||
SWI-compatible predicate. True if _File_ is a loaded Prolog source file.
|
||||
|
||||
SWI-compatible predicate. True if _File_ is a loaded Prolog source file.
|
||||
+ `source_file(? _ModuleAndPred_ ,? _File_)` (prolog_load_context/2 option)
|
||||
|
||||
+ `source_file(? _ModuleAndPred_,? _File_)` (prolog_load_context/2 option)
|
||||
|
||||
SWI-compatible predicate. True if the predicate specified by _ModuleAndPred_ was loaded from file _File_, where _File_ is an absolute path name (see `absolute_file_name/2`).
|
||||
SWI-compatible predicate. True if the predicate specified by _ModuleAndPred_ was loaded from file _File_, where _File_ is an absolute path name (see `absolute_file_name/2`).
|
||||
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
/** @addgroup YAPLibraries Library Predicates
|
||||
/** @addtogroup YAPLibraries Library Predicates
|
||||
|
||||
Library files reside in the library_directory path (set by the
|
||||
`LIBDIR` variable in the Makefile for YAP). Currently,
|
||||
most files in the library are from the Edinburgh Prolog library.
|
||||
|
||||
|
||||
@{
|
||||
|
||||
*/
|
||||
prolog_load_context(directory, DirName) :-
|
||||
( source_location(F, _)
|
||||
@ -1309,22 +1313,20 @@ account the following observations:
|
||||
|
||||
<ul>
|
||||
|
||||
The `reexport` declarations must be the first declarations to
|
||||
follow the `module` declaration.
|
||||
|
||||
<li> The `reexport` declarations must be the first declarations to
|
||||
follow the `module` declaration. </li>
|
||||
|
||||
It is possible to use both `reexport` and `use_module`, but
|
||||
all predicates reexported are automatically available for use in the
|
||||
current module.
|
||||
|
||||
<li> It is possible to use both `reexport` and `use_module`, but all
|
||||
predicates reexported are automatically available for use in the
|
||||
current module. </li>
|
||||
|
||||
In order to obtain efficient execution, YAP compiles dependencies
|
||||
between re-exported predicates. In practice, this means that changing a
|
||||
`reexport` declaration and then *just* recompiling the file
|
||||
may result in incorrect execution.
|
||||
|
||||
<li> In order to obtain efficient execution, YAP compiles
|
||||
dependencies between re-exported predicates. In practice, this means
|
||||
that changing a `reexport` declaration and then *just* recompiling
|
||||
the file may result in incorrect execution. </li>
|
||||
|
||||
</ul>
|
||||
**/
|
||||
*/
|
||||
'$reexport'( TOpts, File, Reexport, Imports, OldF ) :-
|
||||
( Reexport == false -> true ;
|
||||
'$lf_opt'('$parent_topts', TOpts, OldTOpts),
|
||||
@ -1350,6 +1352,7 @@ may result in incorrect execution.
|
||||
This section presents a set of built-ins predicates designed to set the
|
||||
environment for the compiler.
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
|
||||
@ -1498,6 +1501,8 @@ initialization(G,OPT) :-
|
||||
|
||||
@ingroup YAPCompilerSettings
|
||||
|
||||
@{
|
||||
|
||||
Conditional compilation builds on the same principle as
|
||||
term_expansion/2, goal_expansion/2 and the expansion of
|
||||
grammar rules to compile sections of the source-code
|
||||
@ -1679,5 +1684,11 @@ End of conditional compilation.
|
||||
consult_depth(LV) :- '$show_consult_level'(LV).
|
||||
|
||||
/**
|
||||
@}
|
||||
@}
|
||||
|
||||
@}
|
||||
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
|
@ -15,13 +15,6 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
|
||||
@defgroup YAPControl
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
:- system_module( '$_control', [at_halt/1,
|
||||
b_getval/2,
|
||||
break/0,
|
||||
@ -75,6 +68,14 @@
|
||||
|
||||
:- use_system_module( '$coroutining', [freeze_goal/2]).
|
||||
|
||||
/**
|
||||
|
||||
@addtogroup YAPControl
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @pred once(: _G_) is iso
|
||||
|
||||
|
||||
|
@ -15,6 +15,19 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
@defgroup YAPProgramming Programming in YAP
|
||||
|
||||
+ @ref Syntax
|
||||
|
||||
+ @ref YAPCompilerSettings
|
||||
|
||||
+ @ref Indexing
|
||||
|
||||
+ @ref Deb_Interaction
|
||||
|
||||
*/
|
||||
|
||||
:- system_module( '$_directives', [user_defined_directive/2], ['$all_directives'/1,
|
||||
'$exec_directives'/5]).
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: errors.yap *
|
||||
* comments: error messages for YAP *
|
||||
* comments: error messages for YAP *
|
||||
* *
|
||||
* Last rev: $Date: 2008-07-22 23:34:50 $,$Author: vsc $ *
|
||||
* $Log: not supported by cvs2svn $
|
||||
@ -279,7 +279,7 @@ the stream user_error.
|
||||
|
||||
If the Prolog flag verbose is `silent`, messages with
|
||||
_Kind_ `informational`, or `banner` are treated as
|
||||
silent.@c See \cmdlineoption{-q}.
|
||||
silent. See `-q` in [Running_YAP_Interactively].
|
||||
|
||||
This predicate first translates the _Term_ into a list of `message
|
||||
lines` (see print_message_lines/3 for details). Next it will
|
||||
|
@ -62,7 +62,7 @@ atom-garbage collection, perform atom garbage collection at the first
|
||||
opportunity. Initial value is 10,000. May be changed. A value of 0
|
||||
(zero) disables atom garbage collection.
|
||||
|
||||
+ `associate `
|
||||
+ `associate`
|
||||
|
||||
Read-write flag telling a suffix for files associated to Prolog
|
||||
sources. It is `yap` by default.
|
||||
|
@ -14,12 +14,13 @@
|
||||
* comments: initializing the full prolog system *
|
||||
* *
|
||||
*************************************************************************/
|
||||
%% @defgroup YAPBuiltins YAP Built-Ins
|
||||
|
||||
/**
|
||||
|
||||
@addtogroup YAPControl
|
||||
@{
|
||||
/*
|
||||
|
||||
@addtogroup YAPControl
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
:- system_module( '$_init', [!/0,
|
||||
|
@ -15,12 +15,6 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/** @defgroup LoadForeign Access to Foreign Language Programs
|
||||
@ingroup YAPBuiltins
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
|
||||
:- system_module( '$_load_foreign', [load_foreign_files/3,
|
||||
open_shared_object/2,
|
||||
@ -30,6 +24,11 @@
|
||||
|
||||
:- use_system_module( '$_modules', ['$do_import'/3]).
|
||||
|
||||
/** @defgroup LoadForeign Access to Foreign Language Programs
|
||||
@ingroup YAPBuiltins
|
||||
|
||||
*/
|
||||
|
||||
/** @pred load_foreign_files( _Files_, _Libs_, _InitRoutine_)
|
||||
|
||||
should be used, from inside YAP, to load object files produced by the C
|
||||
|
@ -25,7 +25,7 @@ portray messages. These messages range from prompts to error
|
||||
information. All message processing is performed through the builtin
|
||||
print_message/2, in two steps:
|
||||
|
||||
+ The message is processed into a list of commands
|
||||
+ The message is processed into a list of commands
|
||||
+ The commands in the list are sent to the `format/3` builtin
|
||||
in sequence.
|
||||
|
||||
@ -95,7 +95,7 @@ generate_message('$abort') --> !,
|
||||
['YAP execution aborted'].
|
||||
generate_message(abort(user)) --> !,
|
||||
['YAP execution aborted'].
|
||||
generate_message(loading(_,F)) --> F == user, !.
|
||||
generate_message(loading(_,F)) --> { F == user }, !.
|
||||
generate_message(loading(What,FileName)) --> !,
|
||||
[ '~a ~w...' - [What, FileName] ].
|
||||
generate_message(loaded(_,user,_,_,_)) --> !.
|
||||
@ -135,7 +135,7 @@ generate_message(M) -->
|
||||
stack_dump(M).
|
||||
|
||||
stack_dump(error(_,_)) -->
|
||||
{ fail },
|
||||
{ fail },
|
||||
{ recorded(sp_info,local_sp(_P,CP,Envs,CPs),_) },
|
||||
{ Envs = [_|_] ; CPs = [_|_] }, !,
|
||||
[nl],
|
||||
@ -143,7 +143,7 @@ stack_dump(error(_,_)) -->
|
||||
stack_dump(_) --> [].
|
||||
|
||||
prolog_message(X,Y,Z) :-
|
||||
system_message(X,Y,Z).
|
||||
system_message(X,Y,Z).
|
||||
|
||||
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
|
||||
system_message(query(_QueryResult,_)) --> [].
|
||||
@ -553,7 +553,7 @@ syntax_error_token(A) --> !,
|
||||
% Quintus/SICStus/SWI compatibility predicate to print message lines
|
||||
% using a prefix.
|
||||
|
||||
/** @pred print_message_lines(+ _Stream_, + _Prefix_, + _Lines_)
|
||||
/** @pred print_message_lines(+ _Stream_, + _Prefix_, + _Lines_)
|
||||
|
||||
|
||||
Print a message (see print_message/2) that has been translated to
|
||||
@ -576,7 +576,7 @@ A new line is started and if the message is not complete
|
||||
the _Prefix_ is printed too.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
prolog:print_message_lines(_S, _, []) :- !.
|
||||
prolog:print_message_lines(_S, P, [at_same_line|Lines]) :- !,
|
||||
@ -665,7 +665,7 @@ clause_to_indicator(T, M:Name/Arity) :-
|
||||
pred_arity( T1, Name, Arity ).
|
||||
|
||||
pred_arity(V,call,1) :- var(V), !.
|
||||
pred_arity((H:-_),Name,Arity) :-
|
||||
pred_arity((H:-_),Name,Arity) :-
|
||||
nonvar(H),
|
||||
!,
|
||||
functor(H,Name,Arity).
|
||||
|
@ -15,6 +15,78 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
|
||||
@defgroup YAPPackages The YAP packages
|
||||
|
||||
|
||||
@defgroup YAPLibrary The YAP Library
|
||||
|
||||
Library files reside in the library_directory path (set by the
|
||||
`LIBDIR` variable in the Makefile for YAP). Several files in the
|
||||
library are originally from the public-domain Edinburgh Prolog library.
|
||||
|
||||
+ @ref maplist
|
||||
|
||||
+ @ref Apply Apply Macros
|
||||
|
||||
+ @ref Association_Lists
|
||||
|
||||
+ @ref AVL_Trees
|
||||
|
||||
+ @ref Exo_Intervals
|
||||
|
||||
+ @ref Heaps
|
||||
|
||||
+ @ref Lists
|
||||
|
||||
+ @ref LineUtilities
|
||||
|
||||
+ @ref matrix
|
||||
|
||||
+ @ref NonhYBacktrackable_Data_Structures
|
||||
|
||||
+ @ref Ordered_Sets
|
||||
|
||||
+ @ref Pseudo_Random
|
||||
|
||||
+ @ref Queues Queues
|
||||
|
||||
+ @ref PseudoRandom
|
||||
|
||||
+ @ref RedhYBlack_Trees
|
||||
|
||||
+ @ref RegExp
|
||||
|
||||
+ @ref Splay_Trees
|
||||
|
||||
+ @ref System
|
||||
|
||||
+ @ref Terms
|
||||
|
||||
+ @ref Tries
|
||||
|
||||
+ @ref Cleanup
|
||||
|
||||
+ @ref Timeout
|
||||
|
||||
+ @ref Trees
|
||||
|
||||
+ @ref UGraphs
|
||||
|
||||
+ @ref DGraphs
|
||||
|
||||
+ @ref UnDGraphs
|
||||
|
||||
+ @ref DBUsage
|
||||
|
||||
+ @ref lambda
|
||||
|
||||
+ @ref clpfd
|
||||
|
||||
+ @ref Block_Diagram
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
\defgroup YAPModules The YAP Module system
|
||||
@ -22,10 +94,10 @@
|
||||
@ingroup YAPLoading
|
||||
|
||||
The YAP module system is based on the Quintus/SISCtus module
|
||||
system. In this design, modules are named collections of predicates,
|
||||
and all predicates belong to a single module. Predicates are only
|
||||
visible within a module, or _private_ to that module, but the module
|
||||
will most often will also define a list of predicates that are
|
||||
system ˜\cite quintus . In this design, modules are named collections of predicates,
|
||||
and all predicates belong to a single module. By default, predicates are only
|
||||
visible within a module, or _private_ to that module. The module
|
||||
may also define a list of predicates that are
|
||||
_exported_, that is, visible to other modules.
|
||||
|
||||
The main predicates in the module system are:
|
||||
@ -40,7 +112,7 @@ automatically visible to every module. The `system` module was
|
||||
introduced for SWI-Prolog compatibility, and in YAP mostly acts as an
|
||||
alias to `prolog`.
|
||||
|
||||
YAP is always associated to a module, the current <em>source
|
||||
The YAP engine is always associated to a module, the current <em>source
|
||||
module</em> or <em>type-in module</em>. By default, all predicates
|
||||
read-in and all calls to a goal will be made to predicates visible to
|
||||
the current source module, Initially, the source module for YAP is the
|
||||
@ -48,7 +120,7 @@ module `user`. Thus Prolog programs that do not define modules will
|
||||
operate within the `user` module. In this case, all predicates will be
|
||||
visible to all source files.
|
||||
|
||||
YAP also includes a number of libraries and packages, most of them
|
||||
YAP includes a number of libraries and packages, most of them
|
||||
defining their own modules. Note that there is no system mechanism to
|
||||
avoid clashes between module names, so it is up to the programmer to
|
||||
carefully choose the names for her own program modules.
|
||||
@ -112,7 +184,7 @@ YAP and other Prolog systems allow the module prefix to see all
|
||||
predicates visible in the module, including predicates private to the
|
||||
module. This rule allows maximum flexibility, but it also breaks
|
||||
encapsulation and should be used with care. The ciao language proposes
|
||||
a different approach to this problem, see \cite .
|
||||
a different approach to this problem, see \cite DBLP:conf/cl/GrasH00 .
|
||||
|
||||
Modules are not always associated with a source-file. They
|
||||
may range over several files, by using the
|
||||
@ -1472,7 +1544,7 @@ export_list(Module, List) :-
|
||||
'$conj_has_cuts'(G,_,G, _).
|
||||
|
||||
/**
|
||||
set_base_module( +ExportingModule ) is det
|
||||
@pred set_base_module( +ExportingModule ) is det
|
||||
All exported predicates from _ExportingModule_ are automatically available to the
|
||||
current source module.
|
||||
|
||||
@ -1493,7 +1565,7 @@ set_base_module(ExportingModule) :-
|
||||
'$do_error'(type_error(atom,ExportingModule),set_base_module(ExportingModule)).
|
||||
|
||||
/**
|
||||
import_module( +ImportingModule, +ExportingModule ) is det
|
||||
@pred import_module( +ImportingModule, +ExportingModule ) is det
|
||||
All exported predicates from _ExportingModule_ are automatically available to the
|
||||
source module _ImportModule_.
|
||||
|
||||
@ -1512,7 +1584,8 @@ import_module(Mod, EM) :-
|
||||
'$do_error'(type_error(atom,Mod),import_module(Mod, EM)).
|
||||
|
||||
|
||||
/** add_import_module( + _Module_, + _ImportModule_ , +_Pos_) is det
|
||||
/**
|
||||
@pred add_import_module( + _Module_, + _ImportModule_ , +_Pos_) is det
|
||||
Add all exports in _ImportModule_ as available to _Module_.
|
||||
|
||||
|
||||
@ -1542,7 +1615,8 @@ add_import_module(Mod, ImportModule, Pos) :-
|
||||
add_import_module(Mod, ImportModule, Pos) :-
|
||||
'$do_error'(domain_error(start_end,Pos),add_import_module(Mod, ImportModule, Pos)).
|
||||
|
||||
/** delete_import_module( + _ExportModule_, + _ImportModule_ ) is det
|
||||
/**
|
||||
@pred delete_import_module( + _ExportModule_, + _ImportModule_ ) is det
|
||||
Exports in _ImportModule_ are no longer available to _Module_.
|
||||
|
||||
|
||||
@ -1572,7 +1646,8 @@ delete_import_module(Mod, ImportModule) :-
|
||||
'$set_source_module'(Source0, SourceF) :-
|
||||
current_module(Source0, SourceF).
|
||||
|
||||
/** module_property( + _Module_, ? _Property_ ) is nondet
|
||||
/**
|
||||
@pred module_property( + _Module_, ? _Property_ ) is nondet
|
||||
Enumerate non-deterministically the main properties of _Module_ .
|
||||
|
||||
Reports the following properties of _Module_:
|
||||
|
@ -94,12 +94,12 @@ Saves an image of the current state of the YAP database in file
|
||||
Limit for the trail stack.
|
||||
|
||||
+ goal(: _Callable_)
|
||||
Initialization goal for the new executable (see -g).
|
||||
Initialization goal for the new executable (see `-g`).
|
||||
|
||||
+ init_file(+ _Atom_)
|
||||
Default initialization file for the new executable. See -f.
|
||||
Default initialization file for the new executable. See `-f`.
|
||||
|
||||
**/
|
||||
*/
|
||||
qsave_program(File, Opts) :-
|
||||
'$save_program_status'(Opts, qsave_program(File,Opts)),
|
||||
open(File, write, S, [type(binary)]),
|
||||
|
@ -14,9 +14,6 @@
|
||||
* comments: sorting in Prolog *
|
||||
* *
|
||||
*************************************************************************/
|
||||
/** @addtogroup Comparing_Terms
|
||||
@{
|
||||
*/
|
||||
:- system_module( '$_sort', [keysort/2,
|
||||
length/2,
|
||||
msort/2,
|
||||
@ -29,6 +26,9 @@
|
||||
|
||||
:- use_system_module( '$_errors', ['$do_error'/2]).
|
||||
|
||||
/** @addtogroup Comparing_Terms
|
||||
*/
|
||||
|
||||
|
||||
/* The three sorting routines are all variations of merge-sort, done by
|
||||
bisecting the list, sorting the nearly equal halves, and merging the
|
||||
|
@ -16,14 +16,11 @@
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
@addtogroup Threads
|
||||
@defgroup Threads Threads
|
||||
@ingroup YAPExtensions
|
||||
@{
|
||||
@defgroup Threads Threads
|
||||
@ingroup YAPExtensions
|
||||
@{
|
||||
|
||||
@page YAPThreads Threads in YAP
|
||||
|
||||
YAP implements a SWI-Prolog compatible multithreading
|
||||
YAP implements a SWI-Prolog compatible multithreading
|
||||
library. Like in SWI-Prolog, Prolog threads have their own stacks and
|
||||
only share the Prolog <em>heap</em>: predicates, records, flags and other
|
||||
global non-backtrackable data. The package is based on the POSIX thread
|
||||
|
62
pl/yio.yap
62
pl/yio.yap
@ -2,7 +2,7 @@
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
@ -16,18 +16,6 @@
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/** @defgroup InputOutput Input/Output Predicates
|
||||
@ingroup YAPBuiltins
|
||||
@{
|
||||
|
||||
Some of the Input/Output predicates described below will in certain conditions
|
||||
provide error messages and abort only if the file_errors flag is set.
|
||||
If this flag is cleared the same predicates will just fail. Details on
|
||||
setting and clearing this flag are given under 7.7.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
:- system_module( '$_yio', [at_end_of_line/0,
|
||||
at_end_of_line/1,
|
||||
@ -66,6 +54,17 @@ setting and clearing this flag are given under 7.7.
|
||||
|
||||
:- use_system_module( '$_errors', ['$do_error'/2]).
|
||||
|
||||
/** @defgroup InputOutput Input/Output Predicates
|
||||
@ingroup YAPBuiltins
|
||||
|
||||
Some of the Input/Output predicates described below will in certain conditions
|
||||
provide error messages and abort only if the file_errors flag is set.
|
||||
If this flag is cleared the same predicates will just fail. Details on
|
||||
setting and clearing this flag are given under 7.7.
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
/* stream predicates */
|
||||
|
||||
/* check whether a list of options is valid */
|
||||
@ -229,7 +228,7 @@ open_pipe_streams(Read, Write) :-
|
||||
set_stream(Read, encoding(X) ),
|
||||
set_stream(Write, encoding(X) ).
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
|
||||
/** @pred fileerrors
|
||||
@ -258,7 +257,7 @@ Checks if file _F_ exists in the current directory.
|
||||
exists(F) :-
|
||||
absolute_file_name(F, _, [file_errors(fail),access(exist),expand(true)]).
|
||||
|
||||
%%! @addtogroup ReadTerm
|
||||
%! @addtogroup ReadTerm
|
||||
% @{
|
||||
|
||||
/* Term IO */
|
||||
@ -286,9 +285,9 @@ stream.
|
||||
read(Stream,T) :-
|
||||
read_term(Stream, T, []).
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
%%! @addtogroup Write
|
||||
%! @addtogroup Write
|
||||
% @{
|
||||
|
||||
/* meaning of flags for '$write' is
|
||||
@ -328,9 +327,9 @@ display(Stream, T) :-
|
||||
set_value('$portray',true), fail.
|
||||
'$portray'(_) :- set_value('$portray',false), fail.
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
%%! @addtogroup Format
|
||||
%! @addtogroup Format
|
||||
% @{
|
||||
|
||||
/** @pred format(+ _T_)
|
||||
@ -342,9 +341,9 @@ Print formatted output to the current output stream.
|
||||
format(T) :-
|
||||
format(T, []).
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
%%! @addtogroup CharsIO
|
||||
%! @addtogroup CharsIO
|
||||
% @{
|
||||
|
||||
/* character I/O */
|
||||
@ -394,9 +393,9 @@ Outputs a new line to stream user_output.
|
||||
*/
|
||||
ttynl :- nl(user_output).
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
%%! @addtogroup StreamM
|
||||
%! @addtogroup StreamM
|
||||
% @{
|
||||
|
||||
/** @pred current_line_number(- _LineNumber_)
|
||||
@ -534,20 +533,15 @@ current_stream(File, Mode, Stream) :-
|
||||
sformat(String, Form, Args) :-
|
||||
format(codes(String, []), Form, Args).
|
||||
|
||||
%% stream_position_data(?Field, +Pos, ?Date)
|
||||
%
|
||||
% Extract values from stream position objects. '$stream_position' is
|
||||
% of the format '$stream_position'(Byte, Char, Line, LinePos)
|
||||
|
||||
/** @pred stream_position_data(+ _Field_,+ _StreamPosition_,- _Info_)
|
||||
Extract values from stream position objects.
|
||||
|
||||
|
||||
Given the packaged stream position term _StreamPosition_, unify
|
||||
_Info_ with _Field_ `line_count`, `byte_count`, or
|
||||
`char_count`.
|
||||
|
||||
|
||||
|
||||
'$stream_position' is of the format '$stream_position'(Byte, Char,
|
||||
Line, LinePos). Given the packaged stream position term
|
||||
_StreamPosition_, unify _Info_ with _Field_ `line_count`,
|
||||
`byte_count`, or `char_count`.
|
||||
|
||||
*/
|
||||
stream_position_data(Prop, Term, Value) :-
|
||||
@ -576,7 +570,7 @@ stream_position_data(Prop, Term, Value) :-
|
||||
'$set_default_expand'(V) :- !,
|
||||
'$do_error'(domain_error(flag_value,V),yap_flag(open_expands_file_name,V)).
|
||||
|
||||
%%! @}
|
||||
%! @}
|
||||
|
||||
|
||||
'$codes_to_chars'(String0, String, String0) :- String0 == String, !.
|
||||
|
@ -67,7 +67,7 @@ average_country_area(Name, Area) :-
|
||||
|
||||
There are four aggregation predicates, distinguished on two properties.
|
||||
|
||||
$ aggregate vs. aggregate_all :
|
||||
+ aggregate vs. aggregate_all :
|
||||
The aggregate predicates use setof/3 (aggregate/4) or bagof/3
|
||||
(aggregate/3), dealing with existential qualified variables
|
||||
(Var^Goal) and providing multiple solutions for the remaining free
|
||||
@ -76,7 +76,7 @@ There are four aggregation predicates, distinguished on two properties.
|
||||
solution, while aggregate_all/4 uses sort/2 over solutions and
|
||||
Distinguish (see below) generated using findall/3.
|
||||
|
||||
$ The Distinguish argument :
|
||||
+ The Distinguish argument :
|
||||
The versions with 4 arguments provide a Distinguish argument that
|
||||
allow for keeping duplicate bindings of a variable in the result.
|
||||
For example, if we wish to compute the total population of all
|
||||
@ -92,25 +92,25 @@ Template. In addition, they allow for an arbitrary named compound term
|
||||
where each of the arguments is a term from the list below. I.e. the term
|
||||
r(min(X), max(X)) computes both the minimum and maximum binding for X.
|
||||
|
||||
* count
|
||||
* count
|
||||
Count number of solutions. Same as sum(1).
|
||||
* sum(Expr)
|
||||
* sum(Expr)
|
||||
Sum of Expr for all solutions.
|
||||
* min(Expr)
|
||||
* min(Expr)
|
||||
Minimum of Expr for all solutions.
|
||||
* min(Expr, Witness)
|
||||
* min(Expr, Witness)
|
||||
A term min(Min, Witness), where Min is the minimal version
|
||||
of Expr over all Solution and Witness is any other template
|
||||
the applied to the solution that produced Min. If multiple
|
||||
solutions provide the same minimum, Witness corresponds to
|
||||
the first solution.
|
||||
* max(Expr)
|
||||
* max(Expr)
|
||||
Maximum of Expr for all solutions.
|
||||
* max(Expr, Witness)
|
||||
* max(Expr, Witness)
|
||||
As min(Expr, Witness), but producing the maximum result.
|
||||
* set(X)
|
||||
* set(X)
|
||||
An ordered set with all solutions for X.
|
||||
* bag(X)
|
||||
* bag(X)
|
||||
A list of all solutions for X.
|
||||
|
||||
---+++ Acknowledgements
|
||||
|
@ -27,7 +27,7 @@
|
||||
the GNU General Public License.
|
||||
*/
|
||||
|
||||
:- module('$predopts',
|
||||
:- module(predopts,
|
||||
[
|
||||
]).
|
||||
|
||||
|
Reference in New Issue
Block a user