intermediate steo in improving doc system to doxygeb

This commit is contained in:
Vítor Santos Costa 2014-07-26 19:14:15 -05:00
parent ce8a4b6958
commit 325c819f79
24 changed files with 19707 additions and 17834 deletions

View File

@ -55,6 +55,139 @@ static Int p_number_chars( USES_REGS1 );
static Int p_number_codes( USES_REGS1 );
static Int init_current_atom( USES_REGS1 );
static Int cont_current_atom( USES_REGS1 );
static int AlreadyHidden(char *);
static Int p_hide( USES_REGS1 );
static Int p_hidden( USES_REGS1 );
static Int p_unhide( USES_REGS1 );
static int
AlreadyHidden(char *name)
{
AtomEntry *chain;
READ_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, name) != 0)
chain = RepAtom(chain->NextOfAE);
if (EndOfPAEntr(chain))
return (FALSE);
return (TRUE);
}
/** @pred hide(+ _Atom_)
Make atom _Atom_ invisible.
Notice that defining a new atom with the same characters will
result in a different atom.xs
**/
static Int
p_hide( USES_REGS1 )
{ /* hide(+Atom) */
Atom atomToInclude;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR,t1,"hide/1");
return(FALSE);
}
if (!IsAtomTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOM,t1,"hide/1");
return(FALSE);
}
atomToInclude = AtomOfTerm(t1);
if (AlreadyHidden(RepAtom(atomToInclude)->StrOfAE)) {
Yap_Error(SYSTEM_ERROR,t1,"an atom of name %s was already hidden",
RepAtom(atomToInclude)->StrOfAE);
return(FALSE);
}
Yap_ReleaseAtom(atomToInclude);
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
WRITE_LOCK(RepAtom(atomToInclude)->ARWLock);
RepAtom(atomToInclude)->NextOfAE = INVISIBLECHAIN.Entry;
WRITE_UNLOCK(RepAtom(atomToInclude)->ARWLock);
INVISIBLECHAIN.Entry = atomToInclude;
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
return (TRUE);
}
/** @pred hidden( +Atom )
Is the atom _Ãtom_ visible to Prolog?
**/
static Int
p_hidden( USES_REGS1 )
{ /* '$hidden'(+F) */
Atom at;
AtomEntry *chain;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1))
return (FALSE);
if (IsAtomTerm(t1))
at = AtomOfTerm(t1);
else if (IsApplTerm(t1))
at = NameOfFunctor(FunctorOfTerm(t1));
else
return (FALSE);
READ_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
while (!EndOfPAEntr(chain) && AbsAtom(chain) != at)
chain = RepAtom(chain->NextOfAE);
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
if (EndOfPAEntr(chain))
return (FALSE);
return (TRUE);
}
/** @pred unhide(+ _Atom_)
Make hidden atom _Atom_ visible
Note that the operation fails if another atom with name _Atom_ was defined since.
**/
static Int
p_unhide( USES_REGS1 )
{ /* unhide(+Atom) */
AtomEntry *atom, *old, *chain;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR,t1,"unhide/1");
return(FALSE);
}
if (!IsAtomTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOM,t1,"unhide/1");
return(FALSE);
}
atom = RepAtom(AtomOfTerm(t1));
WRITE_LOCK(atom->ARWLock);
if (atom->PropsOfAE != NIL) {
Yap_Error(SYSTEM_ERROR,t1,"cannot unhide an atom in use");
return(FALSE);
}
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
old = NIL;
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, atom->StrOfAE) != 0) {
old = chain;
chain = RepAtom(chain->NextOfAE);
}
if (EndOfPAEntr(chain))
return (FALSE);
atom->PropsOfAE = chain->PropsOfAE;
if (old == NIL)
INVISIBLECHAIN.Entry = chain->NextOfAE;
else
old->NextOfAE = chain->NextOfAE;
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
WRITE_UNLOCK(atom->ARWLock);
return (TRUE);
}
static Int
p_char_code( USES_REGS1 )

View File

@ -310,10 +310,6 @@ static Int cont_current_op( USES_REGS1 );
static Int init_current_atom_op( USES_REGS1 );
static Int cont_current_atom_op( USES_REGS1 );
static Int p_flags( USES_REGS1 );
static int AlreadyHidden(char *);
static Int p_hide( USES_REGS1 );
static Int p_hidden( USES_REGS1 );
static Int p_unhide( USES_REGS1 );
static Int TrailMax(void);
static Int GlobalMax(void);
static Int LocalMax(void);
@ -1170,117 +1166,6 @@ p_set_flag( USES_REGS1 )
return TRUE;
}
static int
AlreadyHidden(char *name)
{
AtomEntry *chain;
READ_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, name) != 0)
chain = RepAtom(chain->NextOfAE);
if (EndOfPAEntr(chain))
return (FALSE);
return (TRUE);
}
static Int
p_hide( USES_REGS1 )
{ /* hide(+Atom) */
Atom atomToInclude;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR,t1,"hide/1");
return(FALSE);
}
if (!IsAtomTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOM,t1,"hide/1");
return(FALSE);
}
atomToInclude = AtomOfTerm(t1);
if (AlreadyHidden(RepAtom(atomToInclude)->StrOfAE)) {
Yap_Error(SYSTEM_ERROR,t1,"an atom of name %s was already hidden",
RepAtom(atomToInclude)->StrOfAE);
return(FALSE);
}
Yap_ReleaseAtom(atomToInclude);
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
WRITE_LOCK(RepAtom(atomToInclude)->ARWLock);
RepAtom(atomToInclude)->NextOfAE = INVISIBLECHAIN.Entry;
WRITE_UNLOCK(RepAtom(atomToInclude)->ARWLock);
INVISIBLECHAIN.Entry = atomToInclude;
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
return (TRUE);
}
static Int
p_hidden( USES_REGS1 )
{ /* '$hidden'(+F) */
Atom at;
AtomEntry *chain;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1))
return (FALSE);
if (IsAtomTerm(t1))
at = AtomOfTerm(t1);
else if (IsApplTerm(t1))
at = NameOfFunctor(FunctorOfTerm(t1));
else
return (FALSE);
READ_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
while (!EndOfPAEntr(chain) && AbsAtom(chain) != at)
chain = RepAtom(chain->NextOfAE);
READ_UNLOCK(INVISIBLECHAIN.AERWLock);
if (EndOfPAEntr(chain))
return (FALSE);
return (TRUE);
}
static Int
p_unhide( USES_REGS1 )
{ /* unhide(+Atom) */
AtomEntry *atom, *old, *chain;
Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) {
Yap_Error(INSTANTIATION_ERROR,t1,"unhide/1");
return(FALSE);
}
if (!IsAtomTerm(t1)) {
Yap_Error(TYPE_ERROR_ATOM,t1,"unhide/1");
return(FALSE);
}
atom = RepAtom(AtomOfTerm(t1));
WRITE_LOCK(atom->ARWLock);
if (atom->PropsOfAE != NIL) {
Yap_Error(SYSTEM_ERROR,t1,"cannot unhide an atom in use");
return(FALSE);
}
WRITE_LOCK(INVISIBLECHAIN.AERWLock);
chain = RepAtom(INVISIBLECHAIN.Entry);
old = NIL;
while (!EndOfPAEntr(chain) && strcmp(chain->StrOfAE, atom->StrOfAE) != 0) {
old = chain;
chain = RepAtom(chain->NextOfAE);
}
if (EndOfPAEntr(chain))
return (FALSE);
atom->PropsOfAE = chain->PropsOfAE;
if (old == NIL)
INVISIBLECHAIN.Entry = chain->NextOfAE;
else
old->NextOfAE = chain->NextOfAE;
WRITE_UNLOCK(INVISIBLECHAIN.AERWLock);
WRITE_UNLOCK(atom->ARWLock);
return (TRUE);
}
void
Yap_show_statistics(void)
{

View File

@ -374,7 +374,7 @@ char *YAPAtom::getName(void) {
}
YAPPredicate::YAPPredicate(const char *s, Term **outp, term_t &vnames) throw (int) {
YAPPredicate::YAPPredicate(const char *s, Term **outp, YAPTerm &vnames) throw (int) {
CACHE_REGS
vnames = Yap_NewSlots(1 PASS_REGS);
Term t = Yap_StringToTerm(s, strlen(s)+1, vnames);
@ -435,8 +435,6 @@ YAPPredicate::YAPPredicate(YAPFunctor f) {
}
void
YAPQuery::initQuery( Term *ts )
{

View File

@ -360,7 +360,7 @@ private:
///
/// It also communicates the array of arguments t[] abd the array of variables
/// back to yapquery
YAPPredicate(const char *s, Term **outp, yhandle_t& vnames ) throw (int);
YAPPredicate(const char *s, Term **outp, YAPTerm& vnames ) throw (int);
/// Term constructor for predicates
///

View File

@ -19,7 +19,7 @@
/**
@group term_t_slots
@groupdef term_t_slots
Also known as term handles, slots are offsets to entries in the local stack. YAP never compresses the local stack, so slots are respected by the garbage collector,
hence providing a way to access terms without being exposed to stack shifts or garbage-collection.

View File

@ -118,7 +118,7 @@ REPEAT_BRIEF = YES
# the entity):The $name class, The $name widget, The $name file, is, provides,
# specifies, contains, represents, a, an and the.
ABBREVIATE_BRIEF = "The $name class" \
ABBREVIATE_BRIEF = "The $name predicate or class" \
"The $name widget" \
"The $name file" \
is \
@ -303,7 +303,8 @@ OPTIMIZE_OUTPUT_FOR_PROLOG = YES
# the files are not read by doxygen.
EXTENSION_MAPPING = md \
pl=Prolog
pl=Prolog \
ypp=Prolog
# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
# according to the Markdown format, which allows for more readable
@ -776,13 +777,17 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
INPUT = /Users/vsc/git/yap-6.3/pl/modules.yap
# INPUT = pl/boot.yap
# INPUT = /Users/vsc/git/yap-6.3/packages/clib/pltotex.pl
# INPUT = /Users/vsc/git/yap-6.3/pl/modules.yap /Users/vsc/git/yap-6.3/packages/real/real.pl # /Users/vsc/git/yap-6.3/CXX
# INPUT = /Users/vsc/git/yap-6.3/pl/absf.yap
# INPUT = /Users/vsc/git/yap-6.3/packages/ProbLog/problog_learning_lbdd.yap
# 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
INPUTX = docs/yap.md \
INPUT = docs/yap.md \
docs/yapdocs.yap \
pl \
C \
H \
@ -855,7 +860,8 @@ FILE_PATTERNS = *.c \
*.as \
*.js \
*.pl \
*.yap
*.yap \
*.ypp
# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.

17462
docs/yap.md

File diff suppressed because it is too large Load Diff

15655
docs/yapdocs.yap Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1259,7 +1259,15 @@ PRED_IMPL("file_name_extension", 3, file_name_extension, 0)
return FALSE;
}
/** @pred prolog_to_os_filename(+ _PrologPath_,- _OsPath_)
This is an SWI-Prolog built-in. Converts between the internal Prolog
pathname conventions and the operating-system pathname conventions. The
internal conventions are Unix and this predicates is equivalent to =/2
(unify) on Unix systems. On DOS systems it will change the
directory-separator, limit the filename length map dots, except for the
last one, onto underscores.
*/
static
PRED_IMPL("prolog_to_os_filename", 2, prolog_to_os_filename, 0)
{ PRED_LD

View File

@ -579,7 +579,36 @@ sort_expand(GlobInfo info)
qsort(ip, is, sizeof(int), compareBagEntries);
}
/**
@addgroup
\pred expand_file_name(+ _WildCard_,- _List_)
This is an SWI-Prolog built-in that unifies _List_ with a sorted list of
files or directories matching _WildCard_. The normal Unix wildcard
constructs <tt>?</tt>, <tt>\\\*</tt>, <tt>[ ... ]</tt> and <tt>{...}</tt> are recognised. The
interpretation of <tt>{...}</tt> is interpreted slightly different from the
C shell (csh(1)). The comma separated argument can be arbitrary
patterns, including <tt>{...}</tt> patterns. The empty pattern is legal as
well: <tt>{.pl,}</tt> matches either <tt>.pl</tt> or the empty string.
If the pattern contains wildcard characters, only existing files and
directories are returned. Expanding a <em>pattern'</em> without wildcard
characters returns the argument, regardless on whether or not it exists.
Before expanding wildcards, the construct $var is expanded to the value
of the environment variable var and a possible leading ~ character is
expanded to the user's home directory. In Windows, the home directory is
determined as follows: if the environment variable `HOME` exists,
this is used. If the variables `HOMEDRIVE` and `HOMEPATH`
exist (Windows-NT), these are used. At initialisation, the system will
set the environment variable `HOME` to point to the YAP home
directory if neither `HOME` nor `HOMEPATH` and
`HOMEDRIVE` are defined.
*/
static
PRED_IMPL("expand_file_name", 2, expand_file_name, 0)
{ PRED_LD

View File

@ -15,6 +15,704 @@
* *
*************************************************************************/
/**
@section MYDDAS MYDDAS
The MYDDAS database project was developed within a FCT project aiming at
the development of a highly efficient deductive database system, based
on the coupling of the MySQL relational database system with the Yap
Prolog system. MYDDAS was later expanded to support the ODBC interface.
@section Requirements_and_Installation_Guide Requirements and Installation Guide
Next, we describe how to usen of the YAP with the MYDDAS System. The
use of this system is entirely depend of the MySQL development libraries
or the ODBC development libraries. At least one of the this development
libraries must be installed on the computer system, otherwise MYDDAS
will not compile. The MySQL development libraries from MySQL 3.23 an
above are know to work. We recommend the usage of MySQL versusODBC,
but it is possible to have both options installed
At the same time, without any problem. The MYDDAS system automatically
controls the two options. Currently, MYDDAS is know to compile without
problems in Linux. The usage of this system on Windows has not been
tested yet. MYDDAS must be enabled at configure time. This can be done
with the following options:
<ul>
<li>--enable-myddas
This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects;
+ --enable-myddas-stats
This option is only available in MySQL. It includes code to get
statistics from the MYDDAS system;
+ --enable-top-level
This option is only available in MySQL. It enables the option to interact with the MySQL server in
two different ways. As if we were on the MySQL Client Shell, and as if
we were using Datalog.
@section MYDDAS_Architecture MYDDAS Architecture
The system includes four main blocks that are put together through the
MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an
ODBC layer and a Prolog to SQL compiler. Current effort is put on the
MySQL interface rather than on the ODBC interface. If you want to use
the full power of the MYDDAS interface we recommend you to use a MySQL
database. Other databases, such as Oracle, PostGres or Microsoft SQL
Server, can be interfaced through the ODBC layer, but with limited
performance and features support.
The main structure of the MYDDAS interface is simple. Prolog queries
involving database goals are translated to SQL using the Prolog to SQL
compiler; then the SQL expression is sent to the database system, which
returns the set of tuples satisfying the query; and finally those tuples
are made available to the Prolog engine as terms. For recursive queries
involving database goals, the YapTab tabling engine provides the
necessary support for an efficient evaluation of such queries.
An important aspect of the MYDDAS interface is that for the programmer
the use of predicates which are defined in database relations is
completely transparent. An example of this transparent support is the
Prolog cut operator, which has exactly the same behaviour from
predicates defined in the Prolog program source code, or from predicates
defined in database as relations.
@section Loading_MYDDAS Loading MYDDAS
Begin by starting YAP and loading the library
`use_module(library(myddas))`. This library already includes the
Prolog to SQL Compiler described in [2] and [1]. In MYDDAS this compiler
has been extended to support further constructs which allow a more
efficient SQL translation.
@section Connecting_to_and_disconnecting_from_a_Database_Server Connecting to and disconnecting from a Database Server
@pred db open(+,+,+,+,+).
@pred db open(+,+,+,+).
@pred db close(+).
Assuming the MySQL server is running and we have an account, we can
login to MySQL by invoking db_open/5 as one of the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_open(mysql,Connection,Host/Database,User,Password).
?- db_open(mysql,Connection,Host/Database/Port,User,Password).
?- db_open(mysql,Connection,Host/Database/UnixSocket,User,Password).
?- db_open(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If the login is successful, there will be a response of `yes`. For
instance:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_open(mysql,con1,localhost/guest_db,guest,'').
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uses the MySQL native interface, selected by the first argument, to open
a connection identified by the `con1` atom, to an instance of a
MySQL server running on host `localhost`, using database guest `db`
and user `guest` with empty `password`. To disconnect from the `con1`
connection we use:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_close(con1).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Alternatively, we can use `db_open/4` and `db_close/0,` without an argument
to identify the connection. In this case the default connection is used,
with atom `myddas`. Thus using
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_open(mysql,localhost/guest_db,guest,'').
?- db_close.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
or
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_open(mysql,myddas,localhost/guest_db,guest,'').
?- db_close(myddas).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
is exactly the same.
MYDDAS also supports ODBC. To connect to a database using an ODBC driver
you must have configured on your system a ODBC DSN. If so, the `db_open/4`
and db_open/5 have the following mode:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_open(odbc,Connection,ODBC_DSN,User,Password).
?- db_open(odbc,ODBC_DSN,User,Password).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For instance, if you do `db_open(odbc,odbc_dsn,guest,'')`. it will connect
to a database, through ODBC, using the definitions on the `odbc_dsn` DSN
configured on the system. The user will be the user `guest` with no
password.
@section Accessing_a_Relation Accessing a Relation
@pred db_import(+Conn,+RelationName,+PredName).
@pred db_import(+RelationName,+PredName).
Assuming you have access permission for the relation you wish to import,
you can use db_import/3 or `db_import/2` as:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_import(Conn,RelationName,PredName).
?- db_import(RelationName,PredName).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
where _RelationName_, is the name of
relation we wish to access, _PredName_ is the name of the predicate we
wish to use to access the relation from YAP. _Conn_, is the connection
identifier, which again can be dropped so that the default myddas connection
is used. For instance, if we want to access the relation phonebook,
using the predicate `phonebook/3` we write:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_import(con1,phonebook,phonebook).
yes
?- phonebook(Letter,Name,Number).
Letter = 'D',
Name = 'John Doe',
Number = 123456789 ?
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Backtracking can then be used to retrieve the next row
of the relation phonebook. Records with particular field values may be
selected in the same way as in Prolog. (In particular, no mode
specification for database predicates is required). For instance:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- phonebook(Letter,'John Doe',Letter).
Letter = 'D',
Number = 123456789 ?
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generates the query
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT A.Letter , 'John Doe' , A.Number
FROM 'phonebook' A
WHERE A.Name = 'John Doe';
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section View_Level_Interface View Level Interface
@pred db view(+,+,+).
@pred db view(+,+).
If we import a database relation, such as an edge relation representing the edges of a directed graph, through
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_import('Edge',edge).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and we then write a query to retrieve all the direct cycles in the
graph, such as
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- edge(A,B), edge(B,A).
A = 10,
B = 20 ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this is clearly inefficient [3], because of relation-level
access. Relation-level access means that a separate SQL query will be
generated for every goal in the body of the clause. For the second
`edge/2` goal, a SQL query is generated using the variable bindings that
result from the first `edge/2` goal execution. If the second
`edge/2` goal
fails, or if alternative solutions are demanded, backtracking access the
next tuple for the first `edge/2` goal and another SQL query will be
generated for the second `edge/2` goal. The generation of this large
number of queries and the communication overhead with the database
system for each of them, makes the relation-level approach inefficient.
To solve this problem the view level interface can be used for the
definition of rules whose bodies includes only imported database
predicates. One can use the view level interface through the predicates
db_view/3 and `db_view/2`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal).
?- db_view(PredName(Arg_1,...,Arg_n),DbGoal).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All arguments are standard Prolog terms. _Arg1_ through _Argn_
define the attributes to be retrieved from the database, while
_DbGoal_ defines the selection restrictions and join
conditions. _Conn_ is the connection identifier, which again can be
dropped. Calling predicate `PredName/n` will retrieve database
tuples using a single SQL query generated for the _DbGoal_. We next show
an example of a view definition for the direct cycles discussed
above. Assuming the declaration:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_import('Edge',edge).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
we
write:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))).
yes
?- direct_cycle(A,B)).
A = 10,
B = 20 ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This call generates the SQL
statement:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT A.attr1 , A.attr2
FROM Edge A , Edge B
WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Backtracking, as in relational level interface, can be used to retrieve the next row of the view.
The view interface also supports aggregate function predicates such as
`sum`, `avg`, `count`, `min` and `max`. For
instance:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_view(count(X),(X is count(B, B^edge(10,B)))).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generates the query :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT COUNT(A.attr2)
FROM Edge A WHERE A.attr1 = 10;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To know how to use db `view/3`, please refer to Draxler's Prolog to
SQL Compiler Manual.
@section Accessing_Tables_in_Data_Sources_Using_SQL Accessing Tables in Data Sources Using SQL
@pred db_sql(+,+,?).
@pred db_sql(+,?).
It is also possible to explicitly send a SQL query to the database server using
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_sql(Conn,SQL,List).
?- db_sql(SQL,List).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
where _SQL_ is an arbitrary SQL expression, and _List_ is a list
holding the first tuple of result set returned by the server. The result
set can also be navigated through backtracking.
Example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_sql('SELECT * FROM phonebook',LA).
LA = ['D','John Doe',123456789] ?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section Insertion_of_Rows Insertion of Rows
@pred db_assert(+,+).
@pred db_assert(+).
Assuming you have imported the related base table using
`db_import/2` or db_import/3, you can insert to that table
by using db_assert/2 predicate any given fact.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_assert(Conn,Fact).
?- db_assert(Fact).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The second argument must be declared with all of its arguments bound to
constants. For example assuming `helloWorld` is imported through
`db_import/2`:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_import('Hello World',helloWorld).
yes
?- db_assert(helloWorld('A' ,'Ana',31)).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This, would generate the following query
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
INSERT INTO helloWorld
VALUES ('A','Ana',3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
which would insert into the helloWorld, the following row:
`A,Ana,31`. If we want to insert `NULL` values into the
relation, we call db_assert/2 with a uninstantiated variable in
the data base imported predicate. For example, the following query on
the YAP-prolog system:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_assert(helloWorld('A',NULL,31)).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Would insert the row: `A,null value,31` into the relation
`Hello World`, assuming that the second row allows null values.
@pred db insert(+,+,+).
@pred db insert(+,+).
This predicate would create a new database predicate, which will insert
any given tuple into the database.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_insert(Conn,RelationName,PredName).
?- db_insert(RelationName,PredName).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This would create a new predicate with name _PredName_, that will
insert tuples into the relation _RelationName_. is the connection
identifier. For example, if we wanted to insert the new tuple
`('A',null,31)` into the relation `Hello World`, we do:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_insert('Hello World',helloWorldInsert).
yes
?- helloWorldInsert('A',NULL,31).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section Types_of_Attributes Types of Attributes
@pred db_get_attributes_types(+,+,?).
@pred db_get_attributes_types(+,?).
The prototype for this predicate is the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_get_attributes_types(Conn,RelationName,ListOfFields).
?- db_get_attributes_types(RelationName,ListOfFields).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can use the
predicate `db_get_attributes types/2` or db_get_attributes_types/3, to
know what are the names and attributes types of the fields of a given
relation. For example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_get_attributes_types(myddas,'Hello World',LA).
LA = ['Number',integer,'Name',string,'Letter',string] ?
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
where <tt>Hello World</tt> is the name of the relation and <tt>myddas</tt> is the
connection identifier.
@section Number_of_Fields Number of Fields
@pred db_number_of_fields(+,?).
@pred db_number_of_fields(+,+,?).
The prototype for this
predicate is the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_number_of_fields(Conn,RelationName,Arity).
?- db_number_of_fields(RelationName,Arity).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can use the predicate db_number_of_fields/2 or
`db_number_of_fields/3` to know what is the arity of a given
relation. Example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_number_of_fields(myddas,'Hello World',Arity).
Arity = 3 ?
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
where `Hello World` is the name of the
relation and `myddas` is the connection identifier.
@section Describing_a_Relation Describing a Relation
@pred db_datalog_describe(+,+).
@pred db_datalog_describe(+).
The db `datalog_describe/2` predicate does not really returns any
value. It simply prints to the screen the result of the MySQL describe
command, the same way as `DESCRIBE` in the MySQL prompt would.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_datalog_describe(myddas,'Hello World').
+----------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
+ Number | int(11) | YES | | NULL | |
+ Name | char(10) | YES | | NULL | |
+ Letter | char(1) | YES | | NULL | |
+----------+----------+------+-----+---------+-------+
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@pred db_describe(+,+).
@pred db_describe(+).
The `db_describe/3` predicate does the same action as
db_datalog_describe/2 predicate but with one major
difference. The results are returned by backtracking. For example, the
last query:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_describe(myddas,'Hello World',Term).
Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ;
Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ;
Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ;
no
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section Enumerating_Relations Enumeration Relations
@pred db_datalog_show_tables(+).
@pred db_datalog_show_tables
If we need to know what relations exists in a given MySQL Schema, we can use
the `db_datalog_show_tables/1` predicate. As <tt>db_datalog_describe/2</tt>,
it does not returns any value, but instead prints to the screen the result of the
`SHOW TABLES` command, the same way as it would be in the MySQL prompt.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_datalog_show_tables(myddas).
+-----------------+
| Tables_in_guest |
+-----------------+
| Hello World |
+-----------------+
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@pred db_show_tables(+, ?).
@pred db_show_tables(?)
The db_show_tables/2 predicate does the same action as
`db_show_tables/1` predicate but with one major difference. The
results are returned by backtracking. For example, given the last query:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_show_tables(myddas,Table).
Table = table('Hello World') ? ;
no
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section The_MYDDAS_MySQL_Top_Level The MYDDAS MySQL Top Level
@pred db_top_level(+,+,+,+,+).
@pred db_top_level(+,+,+,+).
Through MYDDAS is also possible to access the MySQL Database Server, in
the same wthe mysql client. In this mode, is possible to query the
SQL server by just using the standard SQL language. This mode is exactly the same as
different from the standard mysql client. We can use this
mode, by invoking the db top level/5. as one of the following:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_top_level(mysql,Connection,Host/Database,User,Password).
?- db_top_level(mysql,Connection,Host/Database/Port,User,Password).
?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password).
?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Usage is similar as the one described for the db_open/5 predicate
discussed above. If the login is successful, automatically the prompt of
the mysql client will be used. For example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
opens a
connection identified by the `con1` atom, to an instance of a MySQL server
running on host `localhost`, using database guest `db` and user `guest` with
empty password. After this is possible to use MYDDAS as the mysql
client.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_top_level(mysql,con1,localhost/guest_db,guest,'').
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 4468 to server version: 4.0.20
Type 'help;' or '\h' for help.
Type '\c' to clear the buffer.
mysql> exit
Bye
yes
?-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@section Other_MYDDAS_Properties Other MYDDAS Properties
@pred db_verbose(+).
@pred db_top_level(+,+,+,+).
When we ask a question to YAP, using a predicate asserted by
db_import/3, or by db_view/3, this will generate a SQL
`QUERY`. If we want to see that query, we must to this at a given
point in our session on YAP.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_verbose(1).
yes
?-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If we want to
disable this feature, we must call the `db_verbose/1` predicate with the value 0.
@pred db_module(?).
When we create a new database predicate, by using db_import/3,
db_view/3 or db_insert/3, that predicate will be asserted
by default on the `user` module. If we want to change this value, we can
use the db_module/1 predicate to do so.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_module(lists).
yes
?-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By executing this predicate, all of the predicates asserted by the
predicates enumerated earlier will created in the lists module.
If we want to put back the value on default, we can manually put the
value user. Example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_module(user).
yes
?-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We can also see in what module the predicates are being asserted by doing:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_module(X).
X=user
yes
?-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@pred db_my_result_set(?).
The MySQL C API permits two modes for transferring the data generated by
a query to the client, in our case YAP. The first mode, and the default
mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the
information generated to the client side.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_my_result_set(X).
X=store_result
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The other mode that we can use is use result. This one uses the result
set created directly from the server. If we want to use this mode, he
simply do
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- db_my_result_set(use_result).
yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After this command, all
of the database predicates will use use result by default. We can change
this by doing again `db_my_result_set(store_result)`.
@pred db_my_sql_mode(+Conn,?SQL_Mode).
@pred db_my_sql_mode(?SQL_Mode).
The MySQL server allows the user to change the SQL mode. This can be
very useful for debugging proposes. For example, if we want MySQL server
not to ignore the INSERT statement warnings and instead of taking
action, report an error, we could use the following SQL mode.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?-db_my_sql_mode(traditional). yes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You can see the available SQL Modes at the MySQL homepage at
<http://www.mysql.org>.
*/
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
:- load_foreign_files([myddas], [], init_myddas).

View File

@ -1,5 +0,0 @@
# File: Application.mk
NDK_TOOLCHAIN_VERSION = 4.8
APP_STL := stlport_static
APP_CPPFLAGS += -fexceptions
APP_OPTIM := debug

View File

@ -8,7 +8,9 @@
* *
*************************************************************************/
/** @defgroup absf0 File Name Resolution
/** @defgroup YAPAbsoluteFileName File Name Resolution
@ingroup YAPProgramming
Support for file name resolution through absolute_file_name/3 and
friends. These utility built-ins describe a list of directories that
@ -634,3 +636,4 @@ user:file_search_path(path, C) :-
),
lists:member(C, B)
).

View File

@ -33,6 +33,45 @@
:- use_system_module( '$_modules', ['$clean_cuts'/2]).
/** @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:
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:
+ pruning operators, like ->/2 and *->/2
* arithmetic, including early evaluation of constant expressions
* 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_)
Control term expansion during compilation.
Enables low-level optimizations. It reports the current state by
unifying _O_ with the previous state. It then puts YAP in state _N_
(`on` or `off`)/ _On_ is equivalent to compile_expressions/0 and `off`
is equivalent to do_not_compile_expressions/0.
This predicate is useful when debugging, to ensure execution close to the original source.
*/
expand_exprs(Old,New) :-
(get_value('$c_arith',true) ->
Old = on ;
@ -42,8 +81,40 @@ expand_exprs(Old,New) :-
'$set_arith_expan'(on) :- set_value('$c_arith',true).
'$set_arith_expan'(off) :- set_value('$c_arith',[]).
/** @pred compile_expressions
After a call to this predicate, arithmetical expressions will be compiled.
(see example below). This is the default behavior.
*/
compile_expressions :- set_value('$c_arith',true).
/** @pred do_not_compile_expressions
After a call to this predicate, arithmetical expressions will not be compiled.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- source, do_not_compile_expressions.
yes
?- [user].
| p(X) :- X is 2 * (3 + 8).
| :- end_of_file.
?- compile_expressions.
yes
?- [user].
| q(X) :- X is 2 * (3 + 8).
| :- end_of_file.
:- listing.
p(A):-
A is 2 * (3 + 8).
q(A):-
A is 22.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
do_not_compile_expressions :- set_value('$c_arith',[]).
'$c_built_in'(IN, M, OUT) :-
@ -297,5 +368,9 @@ expand_expr(Op, X, Y, O, Q, P) :-
integer(X), \+ '$bignum'(X), !.
'$preprocess_args_for_non_commutative'(X, Y, Z, W, E) :-
'$do_and'(Z = X, Y = W, E).
/**
@}
*/

View File

@ -15,6 +15,174 @@
* *
*************************************************************************/
/** @pred :_P_ , :_Q_ is iso
Conjunction of goals (and).
Example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p(X) :- q(X), r(X).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
should be read as "p( _X_) if q( _X_) and r( _X_)".
*/
/** @pred :_P_ ; :_Q_ is iso
Disjunction of goals (or).
Example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
p(X) :- q(X); r(X).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
should be read as "p( _X_) if q( _X_) or r( _X_)".
*/
/** @pred \+ :_P_ is iso
Goal _P_ is not provable. The execution of this predicate fails if
and only if the goal _P_ finitely succeeds. It is not a true logical
negation, which is impossible in standard Prolog, but
"negation-by-failure".
This predicate might be defined as:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\+(P) :- P, !, fail.
\+(_).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if _P_ did not include "cuts".
*/
/** @pred not :_P_
Goal _P_ is not provable. The same as `\+ _P_`.
This predicate is kept for compatibility with C-Prolog and previous
versions of YAP. Uses of not/1 should be replaced by
`\+`/1, as YAP does not implement true negation.
*/
/** @pred :_P_ -> :_Q_ is iso
Read as "if-then-else" or "commit". This operator is similar to the
conditional operator of imperative languages and can be used alone or
with an else part as follows:
~~~~~
+P -> +Q
~~~~~
"if P then Q".
~~~~~
+P -> +Q; +R
~~~~~
"if P then Q else R".
These two predicates could be defined respectively in Prolog as:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(P -> Q) :- P, !, Q.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(P -> Q; R) :- P, !, Q.
(P -> Q; R) :- R.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if there were no "cuts" in _P_, _Q_ and _R_.
Note that the commit operator works by "cutting" any alternative
solutions of _P_.
Note also that you can use chains of commit operators like:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
P -> Q ; R -> S ; T.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note that `(->)/2` does not affect the scope of cuts in its
arguments.
*/
/** @pred :_Condition_ *-> :_Action_
This construct implements the so-called <em>soft-cut</em>. The control is
defined as follows: If _Condition_ succeeds at least once, the
semantics is the same as ( _Condition_, _Action_). If
_Condition_ does not succeed, the semantics is that of (\\+
_Condition_, _Else_). In other words, If _Condition_
succeeds at least once, simply behave as the conjunction of
_Condition_ and _Action_, otherwise execute _Else_.
The construct _A \*-> B_, i.e. without an _Else_ branch, is
translated as the normal conjunction _A_, _B_.
*/
/** @pred ! is iso
Read as "cut". Cuts any choices taken in the current procedure.
When first found "cut" succeeds as a goal, but if backtracking should
later return to it, the parent goal (the one which matches the head of
the clause containing the "cut", causing the clause activation) will
fail. This is an extra-logical predicate and cannot be explained in
terms of the declarative semantics of Prolog.
example:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
member(X,[X|_]).
member(X,[_|L]) :- member(X,L).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With the above definition
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
?- member(X,[1,2,3]).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
will return each element of the list by backtracking. With the following
definition:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
member(X,[X|_]) :- !.
member(X,[_|L]) :- member(X,L).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
the same query would return only the first element of the
list, since backtracking could not "pass through" the cut.
*/
system_module(_init, _SysExps, _Decls) :- !.
system_module(M, SysExps, Decls) :-
'$current_module'(prolog, M),

View File

@ -70,6 +70,39 @@
'$syntax_check_multiple'/2,
'$syntax_check_single_var'/2]).
/**
@defgroup YAPStyle Checker
@ingroup YAPCompilerSettings
@pred style_check(+ _X_)
Turns on style checking according to the attribute specified by _X_,
which must be one of the following:
+ single_var
Checks single occurrences of named variables in a clause.
+ discontiguous
Checks non-contiguous clauses for the same predicate in a file.
+ multiple
Checks the presence of clauses for the same predicate in more than one
file when the predicate has not been declared as `multifile`
+ all
Performs style checking for all the cases mentioned above.
By default, style checking is disabled in YAP unless we are in
`sicstus` or `iso` language mode.
The style_check/1 built-in is now deprecated. Please use
`set_prolog_flag/1` instead.
@{
**/
%
% A Small style checker for YAP
@ -156,3 +189,17 @@ no_style_check(-multiple) :-
no_style_check([]).
no_style_check([H|T]) :- no_style_check(H), no_style_check(T).
/** @pred discontiguous(+ _G_) is iso
Avoid warnings from the sytax checker.
Declare that the predicate _G_ or list of predicates are discontiguous
procedures, that is, clauses for discontigous procedures may be
separated by clauses from other procedures.
*/
/*
@}
*/

File diff suppressed because it is too large Load Diff

View File

@ -722,17 +722,6 @@ prolog_flag(F, Old, New) :-
prolog_flag(F, Old) :-
current_prolog_flag(F, Old).
% if source_mode is on, then the source for the predicates
% is stored with the code
source_mode(Old,New) :-
'$access_yap_flags'(11,X),
'$transl_to_on_off'(X,Old),
'$transl_to_on_off'(XN,New),
'$set_yap_flags'(11,XN).
source :- '$set_yap_flags'(11,1).
no_source :- '$set_yap_flags'(11,0).
create_prolog_flag(Name, Value, Options) :-
'$check_flag_name'(Name, create_prolog_flag(Name, Value, Options)),
'$check_flag_options'(Options, Domain, RW, create_prolog_flag(Name, Value, Options)),
@ -838,3 +827,47 @@ create_prolog_flag(Name, Value, Options) :-
'$flag_domain_from_value'(_, term).
/**
@pred source_mode(- _O_,+ _N_)
The state of source mode can either be on or off. When the source mode
is on, all clauses are kept both as compiled code and in a "hidden"
database. _O_ is unified with the previous state and the mode is set
according to _N_.
@{
*/
% if source_mode is on, then the source for the predicates
% is stored with the code
source_mode(Old,New) :-
'$access_yap_flags'(11,X),
'$transl_to_on_off'(X,Old),
'$transl_to_on_off'(XN,New),
'$set_yap_flags'(11,XN).
/** @pred source
After executing this goal, YAP keeps information on the source
of the predicates that will be consulted. This enables the use of
[listing/0](@ref listing), `listing/1` and [clause/2](@ref clause) for those
clauses.
The same as `source_mode(_,on)` or as declaring all newly defined
static procedures as `public`.
*/
source :- '$set_yap_flags'(11,1).
/** @pred no_source
The opposite to `source`.
The same as `source_mode(_,off)`.
*/
no_source :- '$set_yap_flags'(11,0).
/**
@}
*/

View File

@ -17,9 +17,9 @@
/**
\defgroup yapmodules The YAP module system
\defgroup YAPModules The YAP Module system
\section syapmods The YAP Module System
@group YAPProgramming
The YAP module system is based on the Quintus/SISCtus module
system. In this design, modules are named collections of predicates,
@ -32,7 +32,7 @@ The main predicates in the module system are:
* module/2 associates a source file to a module. It has two arguments: the name of the new module, and a list of predicates exported by the module.
* use_module/1 and use_module/2 can be used to load a module. They take as first argument the source file for the module. Whereas use_module/1 loads all exported predicates, use_module/2 only takes the ones given by the second argument.
* use_module/1 and use_module/2 can be used to load a module. They take as first argument the source file for the module. Whereas use_module/1 loads all exported predicates, use_module/2 only takes the ones given by the second argument.
YAP pre-defines a number of modules. Most system predicates belong to
the module `prolog`. Predicates from the module `prolog` are
@ -132,90 +132,6 @@ module. Hence after this call:
there will be a `nasa`module in the system, even if nasa:launch/2 is
not at all defined.
\subsection Using_Modules Using Modules
By default, all procedures to consult a file will load the modules
defined therein. The two following declarations allow one to import a
module explicitly. They differ on whether one imports all predicate
declared in the module or not.
\subsection MetahYPredicates_in_Modules Meta-Predicates and Modules
Consider the files opl.pl and rel.pl:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
% opl.pl
:- module(opl,[set_min/2]).
% obtain the smallest value for the last argument of goal G
set_min(G, Min) :-
last_argument( G, A ),
findall( A, call(G, A), Vs),
sort( Vs, [Min|_]).
% rel.pl
:- module(rel,[min_last/2]).
:- use_module(opl).
node(1, 2).
node(1, 4).
node(2, 3).
node(0, 4).
node(1, 4).
min_last(First, Min) :-
rel_min( node(First, V), Min).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Calling `min_last(node(_,_),Min)` should return `Min = 2` and
min_last(node(0,_),Min) should return `Min = 4`. To obtain this
behavior we need to call rel:node/1 from opl:set_min/2. However,
`opl:set_min/2` has no way to know that the goal `G` is from module
`rel`.
The meta_predicate/1 declaration addresses this problem by informing
the compiler that arguments of a predicate are goals, clauses, clauses
heads or other terms related to a module, and that these arguments
must be prefixed with their source module:
In the example we need to declare set_min/2 as a meta-predicate that
calls its first argument:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
:- meta_predicate set_min(0,-).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The 0 in the first argument refers to the use of call/1. The second argument has a mode (output mode) declaration, but this is not used in YAP.
The compiler uses this declaration to rewrite the calls to set_min/1 so that the module of the first argument is made explicit. In the example this corresponds to rewriting min_last/2.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
min_last(First, Min) :-
rel_min( rel:node(First, V), Min).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Note the prefix `rel` before passing the call to node/2.
This process is not entirely transparent. Namely, last_argument/2 is
now forced to deal with the term `rel:node(First, V)`, instead of the
simpler `node(First, V)`. The very useful built-in strip_module/3
extracts the module prefix. We thus obtain:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
last_argument( G, A) :-
strip_module( G, _M, T),
functor(T, _, Arity),
arg(Arity, T, A).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An alternate mechanism is the directive module_transparent/1 that is
offered for compatibility with SWI-Prolog.
\{
**/
@ -304,6 +220,7 @@ and use_module/1 simply gives a warning. As an example, if the file
:- use_module(b).
a(1).
a(X) :- b(X).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and the file `b.pl` contains:
@ -318,24 +235,16 @@ b(1).
YAP will execute as follows:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl
?- use_module(a).
% consulting /Users/vsc/Yap/a.pl...
% consulting /Users/vsc/Yap/b.pl...
% consulted /Users/vsc/Yap/b.pl in module b, 0 msec 0 bytes
%
% Warning:
% at line 5 in /Users/vsc/Yap/a.pl,
% Module a redefines imported predicate b:a/1.
% consulted /Users/vsc/Yap/a.pl in module a, 0 msec 0 bytes
?- [a].
% consulting .../a.pl...
% consulting .../b.pl...
% consulted .../b.pl in module b, 0 msec 0 bytes
% consulted .../a.pl in module a, 1 msec 0 bytes
true.
?- a(X).
X = 1.
?- b(X).
ERROR!!
EXISTENCE ERROR- procedure b/1 is undefined, called from context prolog:$user_call/2
Goal was user:b(_131290)
?- a:b(X).
X = 1 ? ;
X = 1.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -382,8 +291,8 @@ The result is as follows:
YAP 6.3.4 (x86_64-darwin13.3.0): Tue Jul 15 10:42:11 CDT 2014
ERROR!!
at line 3 in /Users/vsc/Yap/bins/threads/d2.pl,
PERMISSION ERROR- loading /Users/vsc/Yap/bins/threads/c.pl: modules d1 and d2 both define b/1
at line 3 in o/d2.pl,
PERMISSION ERROR- loading .../c.pl: modules d1 and d2 both define b/1
?- a(X).
X = 2 ? ;
ERROR!!
@ -391,12 +300,13 @@ X = 2 ? ;
Goal was c:c(_131290)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The state of the module system after this error is actually undefined.
The state of the module system after this error is undefined.
**/
use_module(F) :- '$load_files'(F,
[if(not_loaded),must_be_module(true)], use_module(F)).
[if(not_loaded),must_be_module(true)], use_module(F)).
@ -421,6 +331,7 @@ the graphs library is implemented on top of the red-black trees library, and som
:- use_module(library(rbtrees), [
rb_min/3 as min_assoc,
rb_max/3 as max_assoc,
...]).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -461,11 +372,11 @@ This directive defines the file where it appears as a _module file_;
it must be the first declaration in the file. _Module_ must be an
atom specifying the module name; _ExportList_ must be a list
containing the module's public predicates specification, in the form
`[predicate_name/arity,...]`. The _ExportList_ can also include
`[predicate_name/arity,...]`. The _ExportList_ can include
operator declarations for operators that are exported by the module.
The public predicates of a module file can be made accessible by other
files through loading the source file, using directives
The public predicates of a module file can be made accessible to other
files through loading the source file, using the directives
use_module/1 or use_module/2,
ensure_loaded/1 and the predicates
consult/1 or reconsult/1. The
@ -482,9 +393,22 @@ name with the `:/2` operator.
'$module'(_,N,P) :-
'$module_dec'(N,P).
/**
\pred module(+ M:atom,+ L:list ) is directive
the current file defines module _M_ with exports _L_. The list may include
+ predicatae indicators
+ operator definitions that look like calls to op/3.
The list _L_ may include predicates imported from other modules. If
you want to fully reexport a module, or a sub-set, also consider reexport/1.
*/
/**
\pred module(+ _M_,+ _L_, + _Options_) is directive
define a new module with options
defines a new module with options
Similar to module/2, this directive defines the file where it
appears in as a module file; it must be the first declaration in the file.
@ -504,11 +428,12 @@ The last argument _Options_ must be a list of options, which can be:
+ <b>export(+PredicateIndicator )</b>
Add predicates to the public list of the context module. This implies
the predicate will be imported into another module if this moduleis imported with use_module/1 and use_module/2.
the predicate will be imported into another module if this module
is imported with use_module/1 and use_module/2.
+ <b>export_list(? _Mod_,? _ListOfPredicateIndicator_)</b>
The list _ListOfPredicateIndicator_ contains all predicates
exported by module _Mod_
exported by module _Mod_
Note that predicates are normally exported using the directive
`module/2`. The `export/1` argumwnt is meant to allow export from
@ -600,6 +525,30 @@ of predicates.
'$module_produced by'(M,MI,N1,K1).
/** \pred current_module( ? Mod:atom) is nondet
: _Mod_ is any user-visible module.
*/
current_module(Mod) :-
'$all_current_modules'(Mod),
\+ '$system_module'(Mod).
/** \pred current_module( ? Mod:atom, ? File : file ) is nondet
: _Mod_ is any user-visible module and _File_ its source file, or `user` if none exists.
*/
current_module(Mod,TFN) :-
'$all_current_modules'(Mod),
( recorded('$module','$module'(TFN,Mod,_Publics, _),_) -> true ; TFN = user ).
/** \pred source_module( - Mod:atom ) is nondet
: _Mod_ is the current read-in or source module.
*/
source_module(Mod) :-
'$current_module'(Mod).
% expand module names in a clause
% A1: Input Clause
% A2: Output Class to Compiler (lives in module HM)
@ -872,44 +821,14 @@ expand_goal(G, G).
'$continue_imported'(FM, IM, FPred, Pred).
% module_transparent declaration
%
/** \pred module_transparent( + _Preds_ ) is directive
_Preds_ can access the calling context.
/**
_Preds_ is a comma separated sequence of name/arity predicate
indicators (like in dynamic/1). Each goal associated with a
transparent declared predicate will inherit the context module from
its parent goal.
\defgroup YAPMetaPredicates Using Meta-Calls with Modules
\ingroup YAPModules
*/
@{
:- dynamic('$module_transparent'/4).
'$module_transparent'((P,Ps), M) :- !,
'$module_transparent'(P, M),
'$module_transparent'(Ps, M).
'$module_transparent'(M:D, _) :- !,
'$module_transparent'(D, M).
'$module_transparent'(F/N, M) :-
'$module_transparent'(F,M,N,_), !.
'$module_transparent'(F/N, M) :-
functor(P,F,N),
asserta(prolog:'$module_transparent'(F,M,N,P)),
'$flags'(P, M, Fl, Fl),
NFlags is Fl \/ 0x200004,
'$flags'(P, M, Fl, NFlags).
'$is_mt'(M, H, B, (context_module(CM),B), CM) :-
'$module_transparent'(_, M, _, H), !.
'$is_mt'(M, _, B, B, M).
% meta_predicate declaration
% records $meta_predicate(SourceModule,Functor,Arity,Declaration)
% directive now meta_predicate Ps :- $meta_predicate(Ps).
/** meta_predicate(_G1_,...., _Gn) is directive
\pred meta_predicate(_G1_,...., _Gn) is directive
Declares that this predicate manipulates references to predicates.
Each _Gi_ is a mode specification.
@ -926,7 +845,14 @@ For example, the declaration for call/1 and setof/3 are:
:- meta_predicate call(0), setof(?,0,?).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
meta_predicate declaration
implemented by asserting $meta_predicate(SourceModule,Functor,Arity,Declaration)
*/
% directive now meta_predicate Ps :- $meta_predicate(Ps).
:- dynamic('$meta_predicate'/4).
:- multifile '$meta_predicate'/4.
@ -1036,16 +962,35 @@ For example, the declaration for call/1 and setof/3 are:
'$not_in_vars'(_,[]).
'$not_in_vars'(V,[X|L]) :- X\==V, '$not_in_vars'(V,L).
current_module(Mod) :-
'$all_current_modules'(Mod),
\+ '$system_module'(Mod).
/*
\pred module_transparent( + _Preds_ ) is directive
_Preds_ is a list of predicates that can access the calling context.
current_module(Mod,TFN) :-
'$all_current_modules'(Mod),
( recorded('$module','$module'(TFN,Mod,_Publics, _),_) -> true ; TFN = user ).
_Preds_ is a comma separated sequence of name/arity predicate
indicators (like in dynamic/1). Each goal associated with a
transparent declared predicate will inherit the context module from
its parent goal.
source_module(Mod) :-
'$current_module'(Mod).
*/
:- dynamic('$module_transparent'/4).
'$module_transparent'((P,Ps), M) :- !,
'$module_transparent'(P, M),
'$module_transparent'(Ps, M).
'$module_transparent'(M:D, _) :- !,
'$module_transparent'(D, M).
'$module_transparent'(F/N, M) :-
'$module_transparent'(F,M,N,_), !.
'$module_transparent'(F/N, M) :-
functor(P,F,N),
asserta(prolog:'$module_transparent'(F,M,N,P)),
'$flags'(P, M, Fl, Fl),
NFlags is Fl \/ 0x200004,
'$flags'(P, M, Fl, NFlags).
'$is_mt'(M, H, B, (context_module(CM),B), CM) :-
'$module_transparent'(_, M, _, H), !.
'$is_mt'(M, _, B, B, M).
% comma has its own problems.
:- '$install_meta_predicate'((0,0), prolog).
@ -1150,9 +1095,48 @@ source_module(Mod) :-
\+(2,?,?),
\+ 0 .
%
% get rid of a module and of all predicates included in the module.
%
/**
@}
@{
\defgroup YAPDynamicYAPModules Dynamic Modules
\ingroup YAPModules
YAP (in the footsteps of SWI-Prolog) allows to create modules that
are not bound to files. One application is in Inductive Logic Programming,
where dynamic modules can be used to represent training examples. YAP now include
built-ins to create a module. manipulate its interface, and eventually abolish the
module, releasing all the data therein.
*/
/**
\pred declare_module(+Module, +Super, +File, +Line, +Redefine) is det
declare explicitely a module
Start a new (source-)module _Module_ that inherits all exports from
_Super_. The module is as if defined in file _File_ and _Line_ and if _Redefine_
holds true may
be associated to a new file.
\param[in] _Module_ is the name of the module to declare
\param[in] _MSuper_ is the name of the context module. Use `prolog`or `system`
if you do not need a context.
\param[in] _File_ is the canonical name of the file from which the module is loaded
\param[in] Line is the line-number of the :- module/2 directive.
\param[in] If _Redefine_ `true`, allow associating the module to a new file
*/
'$declare_module'(Name, _Super, Context, _File, _Line) :-
add_import_module(Name, Context, start).
/**
\pred abolish_module( + Mod) is det
get rid of a module and of all predicates included in the module.
*/
abolish_module(Mod) :-
recorded('$module','$module'(_,Mod,_,_),R), erase(R),
fail.
@ -1414,6 +1398,16 @@ export_list(Module, List) :-
'$conj_has_cuts'(G3, DCP, NG3, OK).
'$conj_has_cuts'(G,_,G, _).
/**
set_base_module( +ExportingModule ) is det
All exported predicates from _ExportingModule_ are automatically available to the
current source module.
This built-in was introduced by SWI-Prolog. In YAP, by default, modules only
inherit from `prolog`. This extension allows predicates in the current
module (see module/2 and module/1) to inherit from `user` or other modules.
*/
set_base_module(ExportingModule) :-
var(ExportingModule),
'$do_error'(instantiation_error,set_base_module(ExportingModule)).
@ -1425,6 +1419,16 @@ set_base_module(ExportingModule) :-
set_base_module(ExportingModule) :-
'$do_error'(type_error(atom,ExportingModule),set_base_module(ExportingModule)).
/**
import_module( +ImportingModule, +ExportingModule ) is det
All exported predicates from _ExportingModule_ are automatically available to the
source module _ImportModule_.
This innovation was introduced by SWI-Prolog. By default, modules only
inherit from `prolog`. This extension allows predicates in any module
to inherit from `user`oe other modules.
*/
import_module(Mod, ImportModule) :-
var(Mod),
'$do_error'(instantiation_error,import_module(Mod, ImportModule)).
@ -1476,21 +1480,6 @@ delete_import_module(Mod, ImportModule) :-
'$set_source_module'(Source0, SourceF) :-
current_module(Source0, SourceF).
/**
\pred declare_module(+Module, +Super, +File, +Line, +Redefine) is det
declare explicitely a module
Start a new (source-)module
\param Module is the name of the module to declare
\param File is the canonical name of the file from which the module
is loaded
\param Line is the line-number of the :- module/2 directive.
\param Redefine If `true`, allow associating the module to a new file
*/
'$declare_module'(Name, _Test, Context, _File, _Line) :-
add_import_module(Name, Context, start).
module_property(Mod, class(L)) :-
'$module_class'(Mod, L).
module_property(Mod, line_count(L)) :-
@ -1532,6 +1521,8 @@ ls_imports.
/**
\}
@}
@}
**/

View File

@ -14,7 +14,6 @@
* comments: Predicate Manipulation for YAP: declaration support *
* *
*************************************************************************/
:- system_module( '$_preddecls', [(discontiguous)/1,
(dynamic)/1,
(multifile)/1,
@ -26,6 +25,17 @@
:- use_system_module( '$_errors', ['$do_error'/2]).
/**
@defgroup YAPPredDecls Declaring Properties of Predicates
@ingroup YAPCompilerSettings
The YAP Compiler allows the programmer to include declarations with
important pproprties of predicates, such as where they can be modified
during execution time, whether they are meta-predicates, or whether they can be
defined across multiple files. We next join some of these declarations.
*/
%
% can only do as goal in YAP mode.
%
@ -79,6 +89,56 @@ dynamic(X) :-
'$logical_updatable'(X,Mod) :-
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
/** @pred public( _P_ ) is iso
Instructs the compiler that the source of a predicate of a list of
predicates _P_ must be kept. This source is then accessible through
the clause/2 procedure and through the `listing` family of
built-ins.
Note that all dynamic procedures are public. The `source` directive
defines all new or redefined predicates to be public.
**/
'$public'(X, _) :- var(X), !,
'$do_error'(instantiation_error,public(X)).
'$public'(Mod:Spec, _) :- !,
'$public'(Spec,Mod).
'$public'((A,B), M) :- !, '$public'(A,M), '$public'(B,M).
'$public'([],_) :- !.
'$public'([H|L], M) :- !, '$public'(H, M), '$public'(L, M).
'$public'(A//N1, Mod) :- integer(N1), !,
N is N1+2,
'$public'(A/N, Mod).
'$public'(A/N, Mod) :- integer(N), atom(A), !,
functor(T,A,N),
'$do_make_public'(T, Mod).
'$public'(X, Mod) :-
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
'$do_make_public'(T, Mod) :-
'$is_dynamic'(T, Mod), !. % all dynamic predicates are public.
'$do_make_public'(T, Mod) :-
'$flags'(T,Mod,F,F),
NF is F\/0x00400000,
'$flags'(T,Mod,F,NF).
/** @pred multifile) _P_ ) is iso
A predicate that may be defined in several files.
Instructs the compiler about the declaration of a predicate _P_ in
more than one file. It must appear in the first of the loaded files
where the predicate is declared, and before declaration of any of its
clauses.
Multifile declarations affect [reconsult/1](@ref reconsult) and [compile/1](@ref compile):
when a multifile predicate is reconsulted, only the clauses from the
same file are removed.
Since YAP4.3.0 multifile procedures can be static or dynamic.
**/
multifile(P) :-
'$current_module'(OM),
'$multifile'(P, M).
@ -106,6 +166,14 @@ multifile(P) :-
'$multifile'(P, M) :-
'$do_error'(type_error(predicate_indicator,P),multifile(M:P)).
/** @pred no_style_check(+ _X_)
Turns off style checking according to the attribute specified by
_X_, which has the same meaning as in style_check/1.
The no_style_check/1 built-in is now deprecated. Please use
`set_prolog_flag/1` instead.
**/
discontiguous(V) :-
var(V), !,
'$do_error'(instantiation_error,discontiguous(V)).

View File

@ -728,35 +728,17 @@ dynamic_predicate(P,Sem) :-
'$expand_clause'(H,H1,H1,Mod,HM) :-
strip_module(Mod:H, HM, H1).
'$public'(X, _) :- var(X), !,
'$do_error'(instantiation_error,public(X)).
'$public'(Mod:Spec, _) :- !,
'$public'(Spec,Mod).
'$public'((A,B), M) :- !, '$public'(A,M), '$public'(B,M).
'$public'([],_) :- !.
'$public'([H|L], M) :- !, '$public'(H, M), '$public'(L, M).
'$public'(A//N1, Mod) :- integer(N1), !,
N is N1+2,
'$public'(A/N, Mod).
'$public'(A/N, Mod) :- integer(N), atom(A), !,
functor(T,A,N),
'$do_make_public'(T, Mod).
'$public'(X, Mod) :-
'$do_error'(type_error(callable,X),dynamic(Mod:X)).
'$do_make_public'(T, Mod) :-
'$is_dynamic'(T, Mod), !. % all dynamic predicates are public.
'$do_make_public'(T, Mod) :-
'$flags'(T,Mod,F,F),
NF is F\/0x00400000,
'$flags'(T,Mod,F,NF).
'$is_public'(T, Mod) :-
'$is_dynamic'(T, Mod), !. % all dynamic predicates are public.
'$is_public'(T, Mod) :-
'$flags'(T,Mod,F,F),
F\/0x00400000 =\= 0.
/** @pred stash_predicate(+ _Pred_) @anchor stash_predicate
Make predicate _Pred_ invisible to new code, and to `current_predicate/2`,
`listing`, and friends. New predicates with the same name and
functor can be declared.
**/
stash_predicate(V) :- var(V), !,
'$do_error'(instantiation_error,stash_predicate(V)).
stash_predicate(M:P) :- !,
@ -773,7 +755,11 @@ stash_predicate(P) :-
'$stash_predicate2'(PredDesc, M) :-
'$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)).
/** @pred @pred hide_predicate(+ _Pred_)
Make predicate _Pred_ invisible to `current_predicate/2`,
`listing`, and friends.
**/
hide_predicate(V) :- var(V), !,
'$do_error'(instantiation_error,hide_predicate(V)).
hide_predicate(M:P) :- !,

View File

@ -42,15 +42,64 @@
:- use_system_module( '$_yio', ['$extend_file_search_path'/1]).
/**
@defgroup YAPSaving Saving and Loading Prolog States
@ingroup YAPLoading
YAP can save and read images of its current state to files, known as
saved states. It is possible to save the entire state or just a module
or a file. Notice that saved states in YAP depend on the architecture
where they were made, and may also depend on the version of YAP being
saved.
YAP always tries to find saved states from the current directory
first. If it cannot it will use the environment variable [YAPLIBDIR](@ref YAPLIBDIR), if
defined, or search the default library directory.
*/
/** @pred save_program(+ _F_)
Saves the current state of the data-base in file _F_ .
The result is a resource archive containing a saved state that
expresses all Prolog data from the running program and all
user-defined resources. Depending on the stand_alone option, the
resource is headed by the emulator, a Unix shell script or nothing.
**/
save_program(File) :-
qsave_program(File).
/** @pred save_program(+ _F_, : _G_)
Saves an image of the current state of the YAP database in file
_F_, and guarantee that execution of the restored code will start by
trying goal _G_.
**/
qsave_program(File) :-
'$save_program_status'([], qsave_program(File)),
open(File, write, S, [type(binary)]),
'$qsave_program'(S),
close(S).
/** @pred qsave_program(+ _F_, Opts)
Saves an image of the current state of the YAP database in file
_F_, currently the options in _Opts_ are ignored:
+ stack(+ _KBytes_)
Limit for the local and global stack.
+ trail(+ _KBytes_)
Limit for the trail stack.
+ goal(: _Callable_)
Initialization goal for the new executable (see -g).
+ init_file(+ _Atom_)
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)]),
@ -58,6 +107,12 @@ qsave_program(File, Opts) :-
% make sure we're not going to bootstrap from this file.
close(S).
/** @pred save_program(+ _F_, : _G_)
Saves an image of the current state of the YAP database in file
_F_, and guarantee that execution of the restored code will start by
trying goal _G_.
**/
save_program(File, Goal) :-
recorda('$restore_goal', Goal ,_R),
fail.
@ -241,7 +296,6 @@ save_program(File, _Goal) :-
'$init_from_saved_state_and_args' :-
recorded('$restore_flag', unknown(M:B), R),
erase(R),
writeln(M:B),
yap_flag(M:unknown,B),
fail.
'$init_from_saved_state_and_args' :-
@ -330,9 +384,14 @@ writeln(M:B),
fail.
'$myddas_import_all'.
/** @pred qsave_file(+ _File_, +_State_)
qsave_file(File) :-
recorded('$module', '$module'(F,Mod,Exps,Line), _),
Saves an image of all the information compiled by the systemm from file _F_ to _State_.
This includes modules and predicatees eventually including multi-predicates.
**/
qsave_file(File, State) :-
recorded('$module', '$module'(File,Mod,Exps,Line), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
'$fetch_multi_files_module'(Mod, MFs),
@ -340,14 +399,18 @@ qsave_file(File) :-
'$fetch_module_transparents_module'(Mod, ModTransps),
asserta(Mod:'@mod_info'(F, Exps, Line, Parents, Imps, Metas, ModTransps)),
atom_concat(Mod,'.qly',OF),
open(OF, write, S, [type(binary)]),
open(State, write, S, [type(binary)]),
'$qsave_module_preds'(S, Mod),
close(S),
abolish(Mod:'@mod_info'/7),
fail.
qsave_file(_).
qsave_module(Mod) :-
/** @pred qsave_module(+ _Module_, +_State_)
Saves an image of all the information compiled by the systemm on module _F_ to _State_.
**/
qsave_module(Mod, OF) :-
recorded('$module', '$module'(F,Mod,Exps,L), _),
'$fetch_parents_module'(Mod, Parents),
'$fetch_imports_module'(Mod, Imps),
@ -363,11 +426,21 @@ qsave_module(Mod) :-
fail.
qsave_module(_).
/**
@pred restore(+ _F_)
Restores a previously saved state of YAP from file _F_.
*/
restore(File) :-
open(File, read, S, [type(binary)]),
'$qload_program'(S),
close(S).
/**
@pred qload_module(+ _F_)
Restores a previously saved state of YAP with from file _F_.
*/
qload_module(Mod) :-
atom_concat(Mod,'.qly',IF),
open(IF, read, S, [type(binary)]),

View File

@ -16,6 +16,7 @@
:- use_system_module( '$_errors', ['$do_error'/2]).
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% The YapTab/YapOr/OPTYap systems %%
@ -28,6 +29,12 @@
%% Yap Prolog was developed at University of Porto, Portugal %%
%% %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
/**
YapTab extends the Yap Prolog engine to support sequential tabling. YapOr extends the Yap Prolog engine to support or-parallelism. YapOr extends the Yap Prolog engine to support or-parallelism.
*/
:- meta_predicate
table(:),