doc support
This commit is contained in:
parent
83ec7d9072
commit
137f69ed22
93
C/arith0.c
93
C/arith0.c
@ -18,8 +18,72 @@
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements arithmetic operations
|
||||
/**
|
||||
@file arith0.c
|
||||
|
||||
@defgroup arithmetic_operators Arithmetic Functions
|
||||
@ingroup arithmetic
|
||||
|
||||
YAP implements several arithmetic functions. Arithmetic expressions
|
||||
in YAP may use the following operators:
|
||||
|
||||
- <b>pi [ISO]</b><p> @anchor pi_0
|
||||
|
||||
An approximation to the value of <em>pi</em>, that is, the ratio of a circle's circumference to its diameter.
|
||||
|
||||
- <b>e</b><p> @anchor e_0
|
||||
|
||||
Euler's number, the base of the natural logarithms.
|
||||
|
||||
- <b>epsilon</b><p> @anchor epsilon_0
|
||||
|
||||
The difference between the float `1.0` and the next largest floating point number.
|
||||
|
||||
- <b>inf</b><p> @anchor inf_0
|
||||
|
||||
Infinity according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode.
|
||||
|
||||
Note also that YAP supports `+inf` and `-inf`
|
||||
|
||||
- <b>nan (not a number)</b><p> @anchor nan_0
|
||||
|
||||
Not-a-number according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode.
|
||||
|
||||
- <b>random</b><p> @anchor random_0
|
||||
|
||||
A "random" floating point number between 0 and 1.
|
||||
|
||||
- <b>cputime</b><p> @anchor cputime_0
|
||||
|
||||
CPU time since YAP was invoked, in seconds.
|
||||
|
||||
- <b>heapused</b><p> @anchor heapused_0
|
||||
|
||||
Heap (data-base) space used, in bytes.
|
||||
|
||||
- <b>local</b><p> @anchor local_0
|
||||
|
||||
Local stack in use, in bytes
|
||||
|
||||
- <b>$b</b><p> @anchor b_0
|
||||
|
||||
current choicepoint
|
||||
|
||||
- <b>$env</b><p> @anchor env_0
|
||||
|
||||
Environment
|
||||
|
||||
- <b>$tr</b><p> @anchor tr_0
|
||||
|
||||
Trail in use
|
||||
|
||||
- <b>$free_stack</b><p> @anchor free_stack_0
|
||||
|
||||
Amount of free stack space, that is, free space between global and local stacks.
|
||||
|
||||
- <b>global</b><p> @anchor global_0
|
||||
|
||||
Global stack in use, in bytes.
|
||||
*
|
||||
*/
|
||||
|
||||
@ -89,7 +153,7 @@ eval0(Int fi) {
|
||||
}
|
||||
case op_nan:
|
||||
{
|
||||
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
|
||||
#ifdef _MSC_VER /* Microsoft's Visual C++ Compi<ler */
|
||||
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
|
||||
P = (yamop *)FAILCODE;
|
||||
RERROR();
|
||||
@ -112,40 +176,62 @@ eval0(Int fi) {
|
||||
RFLOAT((Float)Yap_cputime()/1000.0);
|
||||
}
|
||||
case op_heapused:
|
||||
/// - heapused
|
||||
/// Heap (data-base) space used, in bytes.
|
||||
///
|
||||
RINT(HeapUsed);
|
||||
case op_localsp:
|
||||
/// - local
|
||||
/// Local stack in use, in bytes
|
||||
///
|
||||
#if YAPOR_SBA
|
||||
RINT((Int)ASP);
|
||||
#else
|
||||
RINT(LCL0 - ASP);
|
||||
#endif
|
||||
case op_b:
|
||||
/// - $b
|
||||
/// current choicepoint
|
||||
///
|
||||
#if YAPOR_SBA
|
||||
RINT((Int)B);
|
||||
#else
|
||||
RINT(LCL0 - (CELL *)B);
|
||||
#endif
|
||||
case op_env:
|
||||
/// - $env
|
||||
/// Environment
|
||||
///
|
||||
#if YAPOR_SBA
|
||||
RINT((Int)YENV);
|
||||
#else
|
||||
RINT(LCL0 - YENV);
|
||||
#endif
|
||||
case op_tr:
|
||||
/// - $tr
|
||||
/// Trail in use
|
||||
///
|
||||
#if YAPOR_SBA
|
||||
RINT(TR);
|
||||
#else
|
||||
RINT(((CELL *)TR)-LCL0);
|
||||
#endif
|
||||
case op_stackfree:
|
||||
/// - $free_stack
|
||||
///
|
||||
/// Not-a-number according to the IEEE Floating-Point standard. Note that evaluating this term will generate a domain error in the `iso` language mode.
|
||||
RINT(Unsigned(ASP) - Unsigned(HR));
|
||||
case op_globalsp:
|
||||
/// - global
|
||||
/// Global stack in use, in bytes.
|
||||
///
|
||||
#if YAPOR_SBA
|
||||
RINT((Int)HR);
|
||||
#else
|
||||
RINT(HR - H0);
|
||||
#endif
|
||||
}
|
||||
/// end of switch
|
||||
RERROR();
|
||||
}
|
||||
|
||||
@ -210,3 +296,4 @@ Yap_ReInitConstExps(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
211
C/arith1.c
211
C/arith1.c
@ -18,10 +18,212 @@
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements unary arithmetic operations in YAP
|
||||
*
|
||||
*/
|
||||
/**
|
||||
@file arith1.c
|
||||
|
||||
@addtogroup arithmetic_operators
|
||||
|
||||
- <b>exp( _X_) [ISO]</b><p> @anchor exp_1
|
||||
|
||||
Natural exponential.
|
||||
|
||||
- <b>log( _X_) [ISO]</b><p> @anchor log_1
|
||||
|
||||
Natural logarithm.
|
||||
|
||||
- <b>log10( _X_)</b><p> @anchor log10_1
|
||||
|
||||
Decimal logarithm.
|
||||
|
||||
- <b>sqrt( _X_) [ISO]</b><p> @anchor sqrt_1
|
||||
|
||||
Square root.
|
||||
|
||||
- <b>sin( _X_) [ISO]</b><p> @anchor sin_1
|
||||
|
||||
Sine.
|
||||
|
||||
- <b>cos( _X_) [ISO]</b><p> @anchor cos_1
|
||||
|
||||
Cosine.
|
||||
|
||||
- <b>tan( _X_) [ISO]</b><p> @anchor tan_1
|
||||
|
||||
Tangent.
|
||||
|
||||
- <b>asin( _X_) [ISO]</b><p> @anchor asin_1
|
||||
|
||||
Arc sine.
|
||||
|
||||
- <b>acos( _X_) [ISO]</b><p> @anchor acos_1
|
||||
|
||||
Arc cosine.
|
||||
|
||||
- <b>atan( _X_) [ISO]</b><p> @anchor atan_1
|
||||
|
||||
Arc tangent.
|
||||
|
||||
- <b>sinh( _X_)</b><p> @anchor sinh_1
|
||||
|
||||
Hyperbolic sine.
|
||||
|
||||
- <b>cosh( _X_)</b><p> @anchor cosh_1
|
||||
|
||||
Hyperbolic cosine.
|
||||
|
||||
- <b>tanh( _X_)</b><p> @anchor tanh_1
|
||||
|
||||
Hyperbolic tangent.
|
||||
|
||||
- <b>asinh( _X_)</b><p> @anchor asinh_1
|
||||
|
||||
Hyperbolic arc sine.
|
||||
|
||||
- <b>acosh( _X_)</b><p> @anchor acosh_1
|
||||
|
||||
Hyperbolic arc cosine.
|
||||
|
||||
- <b>atanh( _X_)</b><p> @anchor atanh_1
|
||||
|
||||
Hyperbolic arc tangent.
|
||||
|
||||
- <b>lgamma( _X_)</b><p> @anchor lgamma_1
|
||||
|
||||
Logarithm of gamma function.
|
||||
|
||||
- <b>erf( _X_)</b><p> @anchor erf_1
|
||||
|
||||
Gaussian error function.
|
||||
|
||||
- <b>erfc( _X_)</b><p> @anchor erfc_1
|
||||
|
||||
Complementary gaussian error function.
|
||||
|
||||
- <b>random( _X_) [ISO]</b><p> @anchor random_1_op
|
||||
|
||||
An integer random number between 0 and _X_.
|
||||
|
||||
In `iso` language mode the argument must be a floating
|
||||
point-number, the result is an integer and it the float is equidistant
|
||||
it is rounded up, that is, to the least integer greater than _X_.
|
||||
|
||||
- <b>integer( _X_)</b><p> @anchor integer_1_op
|
||||
|
||||
If _X_ evaluates to a float, the integer between the value of _X_ and 0 closest to the value of _X_, else if _X_ evaluates to an
|
||||
integer, the value of _X_.
|
||||
|
||||
- <b>float( _X_) [ISO]</b><p> @anchor float_1_op
|
||||
|
||||
If _X_ evaluates to an integer, the corresponding float, else the float itself.
|
||||
|
||||
- <b>float_fractional_part( _X_) [ISO]</b><p> @anchor float_fractional_part_1
|
||||
|
||||
The fractional part of the floating point number _X_, or `0.0` if _X_ is an integer. In the `iso` language mode, _X_ must be an integer.
|
||||
|
||||
- <b>float_integer_part( _X_) [ISO]</b><p> @anchor float_integer_part_1
|
||||
|
||||
The float giving the integer part of the floating point number _X_, or _X_ if _X_ is an integer. In the `iso` language mode, _X_ must be an integer.
|
||||
|
||||
- <b>abs( _X_) [ISO]</b><p> @anchor abs_1
|
||||
|
||||
The absolute value of _X_.
|
||||
|
||||
- <b>ceiling( _X_) [ISO]</b><p> @anchor ceiling_1
|
||||
|
||||
The integer that is the smallest integral value not smaller than _X_.
|
||||
|
||||
In `iso` language mode the argument must be a floating point-number and the result is an integer.
|
||||
|
||||
- <b>floor( _X_) [ISO]</b><p> @anchor floor_1
|
||||
|
||||
The integer that is the greatest integral value not greater than _X_.
|
||||
|
||||
In `iso` language mode the argument must be a floating
|
||||
point-number and the result is an integer.
|
||||
|
||||
- <b>round( _X_) [ISO]</b><p> @anchor round_1
|
||||
|
||||
The nearest integral value to _X_. If _X_ is equidistant to two integers, it will be rounded to the closest even integral value.
|
||||
|
||||
In `iso` language mode the argument must be a floating point-number, the result is an integer and it the float is equidistant it is rounded up, that is, to the least integer greater than _X_.
|
||||
|
||||
- <b>sign( _X_) [ISO]</b><p> @anchor sign_1
|
||||
|
||||
Return 1 if the _X_ evaluates to a positive integer, 0 it if evaluates to 0, and -1 if it evaluates to a negative integer. If _X_
|
||||
evaluates to a floating-point number return 1.0 for a positive _X_, 0.0 for 0.0, and -1.0 otherwise.
|
||||
|
||||
- <b>truncate( _X_) [ISO]</b><p> @anchor truncate_1
|
||||
|
||||
The integral value between _X_ and 0 closest to _X_.
|
||||
|
||||
- <b>rational( _X_)</b><p> @anchor rational_1_op
|
||||
|
||||
Convert the expression _X_ to a rational number or integer. The function returns the input on integers and rational numbers. For
|
||||
floating point numbers, the returned rational number exactly represents
|
||||
the float. As floats cannot exactly represent all decimal numbers the
|
||||
results may be surprising. In the examples below, doubles can represent
|
||||
`0.25` and the result is as expected, in contrast to the result of
|
||||
`rational(0.1)`. The function `rationalize/1` gives a more
|
||||
intuitive result.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
|
||||
?- A is rational(0.25).
|
||||
|
||||
A is 1 rdiv 4
|
||||
?- A is rational(0.1).
|
||||
A = 3602879701896397 rdiv 36028797018963968
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
- <b>rationalize( _X_)</b><p> @anchor rationalize_1
|
||||
|
||||
Convert the expression _X_ to a rational number or integer. The function is
|
||||
similar to [rational/1](@ref rational_1), but the result is only accurate within the
|
||||
rounding error of floating point numbers, generally producing a much
|
||||
smaller denominator.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
|
||||
?- A is rationalize(0.25).
|
||||
|
||||
A = 1 rdiv 4
|
||||
?- A is rationalize(0.1).
|
||||
|
||||
A = 1 rdiv 10
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
- <b>\\ _X_ [ISO]</b><p>
|
||||
|
||||
Integer bitwise negation.
|
||||
|
||||
- <b>msb( _X_)</b><p> @anchor msb_1
|
||||
|
||||
The most significant bit of the non-negative integer _X_.
|
||||
|
||||
- <b>lsb( _X_)</b><p> @anchor lsb_1
|
||||
|
||||
The least significant bit of the non-negative integer _X_.
|
||||
|
||||
- <b>popcount( _X_)</b><p> @anchor popcount_1
|
||||
|
||||
The number of bits set to `1` in the binary representation of the non-negative integer _X_.
|
||||
|
||||
- <b>[ _X_]</b><p>
|
||||
|
||||
Evaluates to _X_ for expression _X_. Useful because character
|
||||
strings in Prolog are lists of character codes.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
|
||||
X is Y*10+C-"0"
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
is the same as
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
|
||||
X is Y*10+C-[48].
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
which would be evaluated as:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}
|
||||
X is Y*10+C-48.
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
@ -694,6 +896,7 @@ eval1(Int fi, Term t USES_REGS) {
|
||||
RERROR();
|
||||
}
|
||||
}
|
||||
/// end of switch
|
||||
RERROR();
|
||||
}
|
||||
|
||||
|
109
C/arith2.c
109
C/arith2.c
@ -18,10 +18,111 @@
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements unary arithmetic operations in YAP
|
||||
*
|
||||
*/
|
||||
/**
|
||||
|
||||
@file arith2.c
|
||||
|
||||
@addtogroup arithmetic_operators
|
||||
|
||||
These are the binary numeric operators currently supported by YAP.
|
||||
|
||||
- <b> _X_+ _Y_ [ISO]</b><p>
|
||||
|
||||
Sum.
|
||||
|
||||
- <b> _X_- _Y_ [ISO]</b><p>
|
||||
|
||||
Difference.
|
||||
|
||||
- <b> _X_\* _Y_ [ISO]</b><p>
|
||||
|
||||
Product.
|
||||
|
||||
- <b> _X_/ _Y_ [ISO]</b><p>
|
||||
|
||||
Quotient.
|
||||
|
||||
- <b> _X_// _Y_ [ISO]</b><p>
|
||||
|
||||
Integer quotient.
|
||||
|
||||
- <b> _X_ mod _Y_ [ISO]</b><p> @anchor mod_2
|
||||
|
||||
Integer module operator, always positive.
|
||||
|
||||
- <b> _X_ rem _Y_ [ISO]</b><p> @anchor rem_2
|
||||
|
||||
Integer remainder, similar to `mod` but always has the same sign as `X`.
|
||||
|
||||
- <b> _X_ div _Y_ [ISO]</b><p> @anchor div_2
|
||||
|
||||
Integer division, as if defined by `( _X_ - _X_ mod _Y_)// _Y_`.
|
||||
|
||||
- <b> max( _X_, _Y_) [ISO]</b><p> @anchor max_2
|
||||
|
||||
The greater value of _X_ and _Y_.
|
||||
|
||||
- <b> min( _X_, _Y_) [ISO]</b><p> @anchor min_2
|
||||
|
||||
The lesser value of _X_ and _Y_.
|
||||
|
||||
- <b> _X_ ^ _Y_ [ISO]</b><p>
|
||||
|
||||
_X_ raised to the power of _Y_, (from the C-Prolog syntax).
|
||||
|
||||
- <b> exp( _X_, _Y_)</b><p> @anchor exp_2
|
||||
|
||||
_X_ raised to the power of _Y_, (from the Quintus Prolog syntax).
|
||||
|
||||
- <b> _X_ \*\* _Y_ [ISO]</b><p>
|
||||
|
||||
_X_ raised to the power of _Y_ (from ISO).
|
||||
|
||||
- <b> _X_ /\\ _Y_ [ISO]</b><p>
|
||||
|
||||
Integer bitwise conjunction.
|
||||
|
||||
- <b> _X_ \\/ _Y_ [ISO]</b><p>
|
||||
|
||||
Integer bitwise disjunction.
|
||||
|
||||
- <b> _X_ # _Y_</b><p>
|
||||
|
||||
Integer bitwise exclusive disjunction.
|
||||
|
||||
- <b> _X_ \>\< _Y_</b><p>
|
||||
|
||||
Integer bitwise exclusive disjunction.
|
||||
|
||||
- <b> xor( _X_ , _Y_) [ISO]</b><p> @anchor xor_2
|
||||
|
||||
Integer bitwise exclusive disjunction.
|
||||
|
||||
- <b> _X_ \<\< _Y_</b><p>
|
||||
|
||||
Integer bitwise left logical shift of _X_ by _Y_ places.
|
||||
|
||||
- <b> _X_ \>\> _Y_ [ISO]</b><p>
|
||||
|
||||
Integer bitwise right logical shift of _X_ by _Y_ places.
|
||||
|
||||
- <b> gcd( _X_, _Y_)</b><p> @anchor gcd_2
|
||||
|
||||
The greatest common divisor of the two integers _X_ and _Y_.
|
||||
|
||||
- <b> atan( _X_, _Y_)</b><p> @anchor atan_2
|
||||
|
||||
Four-quadrant arc tangent. Also available as `atan2/2`.
|
||||
|
||||
- <b> atan2( _X_, _Y_) [ISO]</b><p> @anchor atan2_2
|
||||
|
||||
Four-quadrant arc tangent.
|
||||
|
||||
- <b> _X_ rdiv _Y_ [ISO]</b><p> @anchor rdiv_2
|
||||
|
||||
Rational division.
|
||||
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
|
75
C/cmppreds.c
75
C/cmppreds.c
@ -14,6 +14,10 @@
|
||||
* comments: comparing two prolog terms *
|
||||
* *
|
||||
*************************************************************************/
|
||||
/// @file cmppreds.c
|
||||
|
||||
|
||||
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
@ -647,6 +651,17 @@ a_cmp(Term t1, Term t2 USES_REGS)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@defgroup arithmetic_cmps Arithmetic Comparison Predicates
|
||||
@ingroup arithmetic
|
||||
|
||||
Comparison of Numeric Expressions. Both arguments must be valid ground expressions at time of call.
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
|
||||
Int
|
||||
Yap_acmp(Term t1, Term t2 USES_REGS)
|
||||
{
|
||||
@ -667,6 +682,15 @@ p_acomp( USES_REGS1 )
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
@class arith_eq_2
|
||||
@brief =:=/2: Equality of arithmetic expressions
|
||||
|
||||
<b>+ _X_ =:= + _Y_ [ISO]</b><p> @anchor ar_eq_2
|
||||
|
||||
|
||||
The value of the expression _X_ is less than the value of expression _Y_.
|
||||
*/
|
||||
static Int
|
||||
a_eq(Term t1, Term t2)
|
||||
{
|
||||
@ -701,6 +725,15 @@ a_eq(Term t1, Term t2)
|
||||
return out == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@class arith_dif_2
|
||||
@brief =\\=/2: Difference of arithmetic expressions
|
||||
|
||||
<b>+ _X_ =\\= + _Y_ [ISO]</b><p> @anchor ar_dif_2
|
||||
|
||||
|
||||
The value of the expression _X_ is different from the value of expression _Y_.
|
||||
*/
|
||||
static Int
|
||||
a_dif(Term t1, Term t2)
|
||||
{
|
||||
@ -710,6 +743,16 @@ a_dif(Term t1, Term t2)
|
||||
return out != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@class arith_gt_2
|
||||
@brief \>/2: Greater than arithmetic expressions
|
||||
|
||||
<b>+ _X_ \> + _Y_ [ISO]</b><p> @anchor qQlg_2
|
||||
|
||||
|
||||
The value of the expression _X_ is less than or equal to the value
|
||||
of expression _Y_.
|
||||
*/
|
||||
static Int
|
||||
a_gt(Term t1, Term t2)
|
||||
{ /* A > B */
|
||||
@ -719,6 +762,16 @@ a_gt(Term t1, Term t2)
|
||||
return out > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@class arith_ge_2
|
||||
@brief \>=/2: Greater than or equal to arithmetic expressions
|
||||
|
||||
<b>+ _X_ \>= + _Y_ [ISO]</b><p> @anchor gGqQ_2
|
||||
|
||||
|
||||
The value of the expression _X_ is greater than or equal to the
|
||||
value of expression _Y_.
|
||||
*/
|
||||
static Int
|
||||
a_ge(Term t1, Term t2)
|
||||
{ /* A >= B */
|
||||
@ -728,6 +781,16 @@ a_ge(Term t1, Term t2)
|
||||
return out >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@class arith_lt_2
|
||||
@brief \</2: Lesser than arithmetic expressions
|
||||
|
||||
<b>+ _X_ \< + _Y_ [ISO]</b><p> @anchor sS_2
|
||||
|
||||
|
||||
The value of the expression _X_ is less than the value of expression
|
||||
_Y_.
|
||||
*/
|
||||
static Int
|
||||
a_lt(Term t1, Term t2)
|
||||
{ /* A < B */
|
||||
@ -737,6 +800,17 @@ a_lt(Term t1, Term t2)
|
||||
return out < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@class arith_le_2
|
||||
@brief =\</2: Lesser than or equal to arithmetic expressions
|
||||
|
||||
<b>+ _X_ =\< + _Y_ [ISO]</b><p> @anchor qQsS_2
|
||||
|
||||
|
||||
The value of the expression _X_ is less than or equal to the value
|
||||
of expression _Y_.
|
||||
*/
|
||||
static Int
|
||||
a_le(Term t1, Term t2)
|
||||
{ /* A <= B */
|
||||
@ -746,6 +820,7 @@ a_le(Term t1, Term t2)
|
||||
return out <= 0;
|
||||
}
|
||||
|
||||
/// @}
|
||||
|
||||
static Int
|
||||
a_noteq(Term t1, Term t2)
|
||||
|
83
C/eval.c
83
C/eval.c
@ -18,10 +18,16 @@
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements arithmetic operations
|
||||
*
|
||||
*/
|
||||
/**
|
||||
@file eval.c
|
||||
|
||||
@defgroup arithmetic_preds Arithmetic Predicates
|
||||
@ingroup arithmetic
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "YapHeap.h"
|
||||
@ -184,6 +190,23 @@ BEAM_is(void)
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
@class is_2
|
||||
@anchor is_2
|
||||
@brief evaluation of arithmetic expressions
|
||||
|
||||
<b>? _X_:number is + _Y_:ground is det</b>
|
||||
|
||||
This predicate succeeds iff the result of evaluating the expression
|
||||
_Y_ unifies with _X_. This is the predicate normally used to
|
||||
perform evaluation of arithmetic expressions:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
X is 2+3*4
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
succeeds with `X = 14`.
|
||||
|
||||
*/
|
||||
|
||||
static Int
|
||||
p_is( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
@ -204,6 +227,16 @@ p_is( USES_REGS1 )
|
||||
return Yap_unify_constant(ARG1,out);
|
||||
}
|
||||
|
||||
/**
|
||||
@class isnan_1
|
||||
@anchor isnan_1
|
||||
@brief True if _X_ is not a number
|
||||
|
||||
<b> isnan(? _X_:float) is det</b>
|
||||
|
||||
Interface to the IEE754 `isnan` test.
|
||||
*/
|
||||
|
||||
static Int
|
||||
p_isnan( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
@ -232,6 +265,17 @@ p_isnan( USES_REGS1 )
|
||||
return isnan(FloatOfTerm(out));
|
||||
}
|
||||
|
||||
/**
|
||||
@class isinf_1
|
||||
@anchor isinf_1
|
||||
@brief True if _X_ is infinity
|
||||
|
||||
<b> isnan(? _X_:float) is det</b>
|
||||
|
||||
Interface to the IEE754 `isinf` test.
|
||||
*/
|
||||
|
||||
|
||||
static Int
|
||||
p_isinf( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
@ -260,6 +304,18 @@ p_isinf( USES_REGS1 )
|
||||
return isinf(FloatOfTerm(out));
|
||||
}
|
||||
|
||||
/**
|
||||
@class logsum_3
|
||||
@anchor logsum_3
|
||||
@brief sum of two logarithms
|
||||
|
||||
<b> logsum(+ _Log1_, + _Log2_, - _Out_ ) is det </b>
|
||||
|
||||
True if _Log1_ is the logarithm of the positive number _A1_,
|
||||
_Log2_ is the logarithm of the positive number _A2_, and
|
||||
_Out_ is the logarithm of the sum of the numbers _A1_ and
|
||||
_A2_. Useful in probability computation.
|
||||
*/
|
||||
static Int
|
||||
p_logsum( USES_REGS1 )
|
||||
{ /* X is Y */
|
||||
@ -391,6 +447,25 @@ static Int cont_between( USES_REGS1 )
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@class between_3
|
||||
@anchor between_3
|
||||
@brief sequence of numbers
|
||||
|
||||
between(+ _Low_:int, + _High_:int, ? _Value_:int) is nondet
|
||||
|
||||
_Low_ and _High_ are integers, _High_ \>= _Low_. If
|
||||
_Value_ is an integer, _Low_ =\< _Value_
|
||||
=\< _High_. When _Value_ is a variable it is successively
|
||||
bound to all integers between _Low_ and _High_. If
|
||||
_High_ is inf or infinite [between/3](@ref between_3) is true iff
|
||||
_Value_ \>= _Low_, a feature that is particularly interesting
|
||||
for generating integers from a certain value.
|
||||
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
static Int
|
||||
init_between( USES_REGS1 )
|
||||
{
|
||||
|
79
H/eval.h
79
H/eval.h
@ -15,6 +15,85 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
|
||||
@defgroup arithmetic Arithmetic in YAP
|
||||
|
||||
@tableofcontents
|
||||
|
||||
YAP supports several different numeric types:
|
||||
<ul>
|
||||
<li><b>Tagged integers</b><p>
|
||||
|
||||
YAP supports integers of word size: 32 bits on 32-bit machines, and
|
||||
64-bits on 64-bit machines.The engine transprently tags smaller
|
||||
integers are tagged so that they fit in a single word. These are the
|
||||
so called <em>tagged integers</em>.
|
||||
|
||||
<li><b>Large integers</b><p>
|
||||
Larger integers that still fit in a cell
|
||||
are represented in the Prolog goal stack. The difference between
|
||||
these integers and tagged integers should be transparent to the programmer.
|
||||
|
||||
</li>
|
||||
<li><b>Multiple Precision Integers</b><p>
|
||||
|
||||
When YAP is built using the GNU multiple precision arithmetic library
|
||||
(GMP), integer arithmetic is unbounded, which means that the size of
|
||||
integers is only limited by available memory. The type of integer
|
||||
support can be detected using the Prolog flags bounded, min_integer
|
||||
and max_integer. As the use of GMP is default, most of the following
|
||||
descriptions assume unbounded integer arithmetic.
|
||||
|
||||
</li> <li><b>Rational numbers (Q)</b><p> Rational numbers are
|
||||
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]
|
||||
(rational division) function.
|
||||
|
||||
</li>
|
||||
<li><b>Floating point numbers</b><p>
|
||||
|
||||
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>
|
||||
|
||||
Arithmetic functions that require integer arguments accept, in addition
|
||||
to integers, rational numbers with denominator `1' and floating point
|
||||
numbers that can be accurately converted to integers. If the required
|
||||
argument is a float the argument is converted to float. Note that
|
||||
conversion of integers to floating point numbers may raise an overflow
|
||||
exception. In all other cases, arguments are converted to the same type
|
||||
using the order integer to rational number to floating point number.
|
||||
|
||||
Evaluation generates the following _Call_
|
||||
exceptions:
|
||||
|
||||
@exception "error(instantiation_error, Call )" if not ground
|
||||
|
||||
@exception "type_error(evaluable( V ), Call)" if not evaluable term
|
||||
@exception "type_error(integer( V ), Call)" if must be integer
|
||||
@exception "type_error(float( V ), Call)" if must be float
|
||||
|
||||
@exception "domain_error(out_of_range( V ), Call)" if argument invalid
|
||||
@exception "domain_error(not_less_than_zero( V ), Call)" if argument must be positive or zero
|
||||
|
||||
@exception "evaluation_error(undefined( V ), Call)" result is not defined (nan)
|
||||
@exception "evaluation_error(overflow( V ), Call)" result is arithmetic overflow
|
||||
|
||||
@secreflist
|
||||
@refitem is_2
|
||||
@refitem isnan_1
|
||||
@endsecreflist
|
||||
|
||||
|
||||
**/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/* C library used to implement floating point functions */
|
||||
|
@ -298,6 +298,7 @@ PLCONS_SOURCES = \
|
||||
|
||||
PL_SOURCES= \
|
||||
pl/arith.yap \
|
||||
pl/arithpreds.yap \
|
||||
pl/arrays.yap \
|
||||
pl/attributes.yap \
|
||||
pl/atoms.yap \
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
@node Built-ins, Library, Modules, Top
|
||||
|
||||
@chapter Built-In Predicates Library
|
||||
|
||||
@menu
|
||||
|
||||
Built-ins, Debugging, Syntax, Top
|
||||
@ -13,7 +15,7 @@ Built-ins, Debugging, Syntax, Top
|
||||
* Predicates on Characters:: Manipulating Characters
|
||||
* Comparing Terms:: Comparison of Terms
|
||||
* Arithmetic:: Arithmetic in YAP
|
||||
* I/O:: Input/Output with YAP
|
||||
* Input/Output:: Input/Output with YAP
|
||||
* Database:: Modifying Prolog's Database
|
||||
* Sets:: Finding All Possible Solutions
|
||||
* Grammars:: Grammar Rules
|
||||
@ -30,7 +32,7 @@ Built-ins, Debugging, Syntax, Top
|
||||
@end menu
|
||||
|
||||
@node Control, Undefined Procedures, , Top
|
||||
@chapter Control Predicates
|
||||
@section Control Predicates
|
||||
|
||||
|
||||
This chapter describes the predicates for controlling the execution of
|
||||
@ -696,7 +698,7 @@ Translates a message-term into a string object. Primarily intended for SWI-Prolo
|
||||
@end table
|
||||
|
||||
@node Testing Terms, Predicates on Atoms, Messages, Top
|
||||
@chapter Predicates on terms
|
||||
@section Predicates on terms
|
||||
|
||||
@table @code
|
||||
|
||||
@ -1194,8 +1196,7 @@ the call.
|
||||
|
||||
@item digit(@var{Weight})
|
||||
@var{Char} is a digit with value
|
||||
@var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X =
|
||||
'6'}. Useful for parsing numbers.
|
||||
@var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X = '6'}. Useful for parsing numbers.
|
||||
|
||||
@item xdigit(@var{Weight})
|
||||
@var{Char} is a hexa-decimal digit with value @var{Weight}. I.e. char_type(a, xdigit(X) yields X = '10'. Useful for parsing numbers.
|
||||
@ -1412,9 +1413,21 @@ of length @var{S}.
|
||||
|
||||
@end table
|
||||
|
||||
@node Arithmetic, I/O, Comparing Terms, Top
|
||||
@node Arithmetic, Input/Output, Comparing Terms, Top
|
||||
@section Arithmetic
|
||||
|
||||
@ifplaintext
|
||||
@copydoc arithmetic
|
||||
|
||||
See @ref arithmetic_preds for the predicates that implement arithment
|
||||
|
||||
See @ref arithmetic_cmps for the arithmetic comparisons supported in YAP
|
||||
|
||||
See @ref arithmetic_operators for how to call arithmetic operations in YAP
|
||||
|
||||
@end ifplaintext
|
||||
|
||||
@texinfo
|
||||
YAP now supports several different numeric types:
|
||||
|
||||
@table @code
|
||||
@ -1440,7 +1453,8 @@ YAP now supports several different numeric types:
|
||||
numbers that are returned from is/2 are canonical, which means M
|
||||
is positive and N and M have no common divisors. Rational numbers
|
||||
are introduced in the computation using the rational/1,
|
||||
rationalize/1 or the rdiv/2 (rational division) function.
|
||||
rationalize/1 or the
|
||||
rdiv/2 (rational division) function.
|
||||
|
||||
@item float
|
||||
Floating point numbers are represented using the C-type double. On most today platforms these are 64-bit IEEE floating point numbers.
|
||||
@ -1491,8 +1505,7 @@ Integer remainder, similar to @code{mod} but always has the same sign
|
||||
@code{X}.
|
||||
|
||||
@item @var{X} div @var{Y} [ISO]
|
||||
Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y})
|
||||
// @var{Y}}.
|
||||
Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y})// @var{Y}}.
|
||||
|
||||
@item exp(@var{X}) [ISO]
|
||||
Natural exponential.
|
||||
@ -1767,6 +1780,7 @@ The primitive YAP predicates involving arithmetic expressions are:
|
||||
|
||||
@table @code
|
||||
|
||||
@itemize
|
||||
@item @var{X} is +@var{Y} [2]
|
||||
@findex is/2
|
||||
@syindex is/2
|
||||
@ -1780,6 +1794,7 @@ X is 2+3*4
|
||||
@end example
|
||||
@noindent
|
||||
succeeds with @code{X = 14}.
|
||||
@end itemize
|
||||
|
||||
@item +@var{X} < +@var{Y} [ISO]
|
||||
@findex </2
|
||||
@ -1852,7 +1867,6 @@ will be thrown back to the top-level.
|
||||
The following predicates provide counting:
|
||||
|
||||
@table @code
|
||||
|
||||
@item between(+@var{Low}, +@var{High}, ?@var{Value})
|
||||
@findex between/3
|
||||
@syindex between/3
|
||||
@ -1907,13 +1921,16 @@ The following predicates provide counting:
|
||||
@cnindex isinf/1
|
||||
True if floating point expression @var{Float} evaluates to infinity.
|
||||
|
||||
|
||||
@end table
|
||||
|
||||
@node I/O, Database, Arithmetic, Top
|
||||
@chapter I/O Predicates
|
||||
@end texinfo
|
||||
|
||||
Some of the I/O predicates described below will in certain conditions
|
||||
|
||||
|
||||
@node Input/Output, Database, Arithmetic, Top
|
||||
@section Input/Output Predicates
|
||||
|
||||
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.
|
||||
@ -1923,16 +1940,16 @@ setting and clearing this flag are given under 7.7.
|
||||
Subnodes of Input/Output
|
||||
* Streams and Files:: Handling Streams and Files
|
||||
* C-Prolog File Handling:: C-Prolog Compatible File Handling
|
||||
* I/O of Terms:: Input/Output of terms
|
||||
* I/O of Characters:: Input/Output of Characters
|
||||
* I/O for Streams:: Input/Output using Streams
|
||||
* C-Prolog to Terminal:: C-Prolog compatible Character I/O to terminal
|
||||
* I/O Control:: Controlling your Input/Output
|
||||
* Input/Output of Terms:: Input/Output of terms
|
||||
* Input/Output of Characters:: Input/Output of Characters
|
||||
* Input/Output for Streams:: Input/Output using Streams
|
||||
* C-Prolog to Terminal:: C-Prolog compatible Character Input/Output to terminal
|
||||
* Input/Output Control:: Controlling your Input/Output
|
||||
* Sockets:: Using Sockets from YAP
|
||||
|
||||
@end menu
|
||||
|
||||
@node Streams and Files, C-Prolog File Handling, , I/O
|
||||
@node Streams and Files, C-Prolog File Handling, , Input/Output
|
||||
@section Handling Streams and Files
|
||||
|
||||
@table @code
|
||||
@ -2002,7 +2019,7 @@ wide character and encoding issues.
|
||||
@item representation_errors(+@var{Mode})
|
||||
Change the behaviour when writing characters to the stream that cannot
|
||||
be represented by the encoding. The behaviour is one of @code{error}
|
||||
(throw and I/O error exception), @code{prolog} (write @code{\u...\}
|
||||
(throw and Input/Output error exception), @code{prolog} (write @code{\u...\}
|
||||
escape code or @code{xml} (write @code{&#...;} XML character entity).
|
||||
The initial mode is @code{prolog} for the user streams and
|
||||
@code{error} for all other streams. See also @ref{Encoding}.
|
||||
@ -2048,6 +2065,12 @@ Unify the last modification time of @var{File} with
|
||||
@var{Time}. @var{Time} is a floating point number expressing the seconds
|
||||
elapsed since Jan 1, 1970.
|
||||
|
||||
@item access_file(+@var{F},+@var{M})
|
||||
@findex access_file/2
|
||||
Is the file accessible?
|
||||
|
||||
@texinfo
|
||||
|
||||
@item absolute_file_name(+@var{Name},+@var{Options}, -@var{FullPath}) absolute_file_name(+@var{Name}, -@var{FullPath},+@var{Options})
|
||||
@findex absolute_file_name/3
|
||||
@syindex absolute_file_name/3
|
||||
@ -2111,6 +2134,7 @@ If the last argument is a list and the 2nd not, the arguments are
|
||||
swapped, making the call @code{absolute_file_name}(+@var{Spec}, -@var{Path},
|
||||
+@var{Options}) valid as well.
|
||||
|
||||
|
||||
@item absolute_file_name(+@var{Name},-@var{FullPath})
|
||||
@findex absolute_file_name/2
|
||||
@syindex absolute_file_name/2
|
||||
@ -2119,6 +2143,8 @@ Give the path a full path @var{FullPath} YAP would use to consult a file
|
||||
named @var{Name}. Unify @var{FullPath} with @code{user} if the file
|
||||
name is @code{user}.
|
||||
|
||||
@end texinfo
|
||||
|
||||
@item file_base_name(+@var{Name},-@var{FileName})
|
||||
@findex file_base_name/2
|
||||
@snindex file_base_name/2
|
||||
@ -2223,7 +2249,7 @@ past-end-of-stream.
|
||||
@cnindex at_end_of_stream/1
|
||||
Succeed if the stream @var{S} has stream position end-of-stream or
|
||||
past-end-of-stream. Note that @var{S} must be a readable stream.
|
||||
|
||||
|
||||
@item set_stream_position(+@var{S}, +@var{POS}) [ISO]
|
||||
@findex set_stream_position/2
|
||||
@syindex set_stream_position/2
|
||||
@ -2297,7 +2323,7 @@ overview of wide character and encoding issues in YAP.
|
||||
@item representation_errors(+@var{Mode})
|
||||
Behaviour when writing characters to the stream that cannot be
|
||||
represented by the encoding. The behaviour is one of @code{error}
|
||||
(throw and I/O error exception), @code{prolog} (write @code{\u...\}
|
||||
(throw and Input/Output error exception), @code{prolog} (write @code{\u...\}
|
||||
escape code or @code{xml} (write @code{&#...;} XML character entity).
|
||||
The initial mode is @code{prolog} for the user streams and
|
||||
@code{error} for all other streams. See also @ref{Encoding} and
|
||||
@ -2355,7 +2381,7 @@ Given the packaged stream position term @var{StreamPosition}, unify
|
||||
|
||||
@end table
|
||||
|
||||
@node C-Prolog File Handling, I/O of Terms, Streams and Files, I/O
|
||||
@node C-Prolog File Handling, Input/Output of Terms, Streams and Files, Input/Output
|
||||
@section C-Prolog File Handling
|
||||
|
||||
@table @code
|
||||
@ -2423,7 +2449,8 @@ Closes the current input stream (see 6.7.).
|
||||
|
||||
@end table
|
||||
|
||||
@node I/O of Terms, I/O of Characters, C-Prolog File Handling, I/O
|
||||
|
||||
@node Input/Output of Terms, Input/Output of Characters, C-Prolog File Handling, Input/Output
|
||||
@section Handling Input/Output of Terms
|
||||
|
||||
@table @code
|
||||
@ -2859,7 +2886,7 @@ X = [104, 101, 108, 108, 111]
|
||||
|
||||
@end table
|
||||
|
||||
@node I/O of Characters, I/O for Streams, I/O of Terms, I/O
|
||||
@node Input/Output of Characters, Input/Output for Streams, Input/Output of Terms, Input/Output
|
||||
@section Handling Input/Output of Characters
|
||||
|
||||
@table @code
|
||||
@ -2988,7 +3015,7 @@ Outputs a new line to the current output stream.
|
||||
|
||||
@end table
|
||||
|
||||
@node I/O for Streams, C-Prolog to Terminal, I/O of Characters, I/O
|
||||
@node Input/Output for Streams, C-Prolog to Terminal, Input/Output of Characters, Input/Output
|
||||
@section Input/Output Predicates applied to Streams
|
||||
|
||||
@table @code
|
||||
@ -3154,8 +3181,8 @@ Outputs a new line to stream @var{S}.
|
||||
|
||||
@end table
|
||||
|
||||
@node C-Prolog to Terminal, I/O Control, I/O for Streams, I/O
|
||||
@section Compatible C-Prolog predicates for Terminal I/O
|
||||
@node C-Prolog to Terminal, Input/Output Control, Input/Output for Streams, Input/Output
|
||||
@section Compatible C-Prolog predicates for Terminal Input/Output
|
||||
|
||||
@table @code
|
||||
|
||||
@ -3198,7 +3225,7 @@ Outputs a new line to stream @code{user_output}.
|
||||
|
||||
@end table
|
||||
|
||||
@node I/O Control, Sockets, C-Prolog to Terminal, I/O
|
||||
@node Input/Output Control, Sockets, C-Prolog to Terminal, Input/Output
|
||||
@section Controlling Input/Output
|
||||
|
||||
@table @code
|
||||
@ -3223,7 +3250,7 @@ opened or closed.
|
||||
@syindex fileerrors/0
|
||||
@cyindex fileerrors/0
|
||||
Switches on the file_errors flag so that in certain error conditions
|
||||
I/O predicates will produce an appropriated message and abort.
|
||||
Input/Output predicates will produce an appropriated message and abort.
|
||||
|
||||
@item always_prompt_user
|
||||
@findex always_prompt_user/0
|
||||
@ -3235,15 +3262,15 @@ interactive control from a pipe or a socket.
|
||||
|
||||
@end table
|
||||
|
||||
@node Sockets, , I/O Control, I/O
|
||||
@node Sockets, , Input/Output Control, Input/Output
|
||||
@section Using Sockets From YAP
|
||||
|
||||
YAP includes a SICStus Prolog compatible socket interface. In YAP-6.3
|
||||
this uses the @c{clib} package to emulate the old low level interface that
|
||||
this uses the @code{clib} package to emulate the old low level interface that
|
||||
provides direct access to the major socket system calls. These calls
|
||||
can be used both to open a new connection in the network or connect to
|
||||
a networked server. Socket connections are described as read/write
|
||||
streams, and standard I/O built-ins can be used to write on or read
|
||||
streams, and standard Input/Output built-ins can be used to write on or read
|
||||
from sockets. The following calls are available:
|
||||
|
||||
@table @code
|
||||
@ -3394,8 +3421,8 @@ address in number and dots notation.
|
||||
|
||||
@end table
|
||||
|
||||
@node Database, Sets, I/O, Top
|
||||
@chapter Using the Clausal Data Base
|
||||
@node Database, Sets, Input/Output, Top
|
||||
@section Using the Clausal Data Base
|
||||
|
||||
Predicates in YAP may be dynamic or static. By default, when
|
||||
consulting or reconsulting, predicates are assumed to be static:
|
||||
@ -4204,7 +4231,7 @@ no
|
||||
@end table
|
||||
|
||||
@node Grammars, OS, Sets, Top
|
||||
@chapter Grammar Rules
|
||||
@section Grammar Rules
|
||||
|
||||
Grammar rules in Prolog are both a convenient way to express definite
|
||||
clause grammars and an extension of the well known context-free grammars.
|
||||
@ -4319,7 +4346,7 @@ This predicate is used by the grammar rules compiler and is defined as
|
||||
@end table
|
||||
|
||||
@node OS, Term Modification, Grammars, Top
|
||||
@chapter Access to Operating System Functionality
|
||||
@section Access to Operating System Functionality
|
||||
|
||||
The following built-in predicates allow access to underlying
|
||||
Operating System functionality:
|
||||
@ -4548,7 +4575,7 @@ order of dispatch.
|
||||
@end table
|
||||
|
||||
@node Term Modification, Global Variables, OS, Top
|
||||
@chapter Term Modification
|
||||
@section Term Modification
|
||||
|
||||
@cindex updating terms
|
||||
It is sometimes useful to change the value of instantiated
|
||||
@ -4598,7 +4625,7 @@ Set the current value of mutable term @var{M} to term @var{D}.
|
||||
@end table
|
||||
|
||||
@node Global Variables, Profiling, Term Modification, Top
|
||||
@chapter Global Variables
|
||||
@section Global Variables
|
||||
|
||||
@cindex global variables
|
||||
|
||||
@ -4804,7 +4831,7 @@ compound terms.
|
||||
|
||||
|
||||
@node Profiling, Call Counting, Global Variables, Top
|
||||
@chapter Profiling Prolog Programs
|
||||
@section Profiling Prolog Programs
|
||||
|
||||
@cindex profiling
|
||||
|
||||
@ -4938,7 +4965,7 @@ Show profiling info for the top-most @var{N} predicates.
|
||||
The @code{showprofres/0} and @code{showprofres/1} predicates call a user-defined multifile hook predicate, @code{user:prolog_predicate_name/2}, that can be used for converting a possibly explicitly-qualified callable term into an atom that will used when printing the profiling information.
|
||||
|
||||
@node Call Counting, Arrays, Profiling, Top
|
||||
@chapter Counting Calls
|
||||
@section Counting Calls
|
||||
|
||||
@cindex Counting Calls
|
||||
Predicates compiled with YAP's flag @code{call_counting} set to
|
||||
@ -5014,7 +5041,7 @@ exception when @code{l/0} performs more than 10000 reductions.
|
||||
|
||||
|
||||
@node Arrays, Preds, Call Counting , Top
|
||||
@chapter Arrays
|
||||
@section Arrays
|
||||
|
||||
The YAP system includes experimental support for arrays. The
|
||||
support is enabled with the option @code{YAP_ARRAYS}.
|
||||
@ -5223,7 +5250,7 @@ terms.
|
||||
@end table
|
||||
|
||||
@node Preds, Misc, Arrays, Top
|
||||
@chapter Predicate Information
|
||||
@section Predicate Information
|
||||
|
||||
Built-ins that return information on the current predicates and modules:
|
||||
|
||||
@ -5247,7 +5274,7 @@ Succeeds if @var{M} are current modules associated to the file @var{F}.
|
||||
@end table
|
||||
|
||||
@node Misc, , Preds, Top
|
||||
@chapter Miscellaneous
|
||||
@section Miscellaneous
|
||||
|
||||
@table @code
|
||||
|
||||
@ -5322,9 +5349,8 @@ garbage collection and stack shifts time included.
|
||||
Size of static code in YAP in bytes: @var{Clause Size}, the number of
|
||||
bytes allocated for clauses, plus
|
||||
@var{Index Size}, the number of bytes spent in the indexing code. The
|
||||
indexing code is divided into main tree, @var{Tree Index
|
||||
Size}, tables that implement choice-point manipulation, @var{Choice Point Instructions
|
||||
Size}, tables that cache clauses for future expansion of the index
|
||||
indexing code is divided into main tree, @var{Tree Index Size},
|
||||
tables that implement choice-point manipulation, @var{Choice xsPoint Instructions Size}, tables that cache clauses for future expansion of the index
|
||||
tree, @var{Expansion Nodes Size}, and
|
||||
tables such as hash tables that select according to value, @var{Index Switch Size}.
|
||||
|
||||
@ -5388,8 +5414,7 @@ available using @code{yap_flag(gc_trace,verbose)}.
|
||||
Size of static code in YAP in bytes: @var{Clause Size}, the number of
|
||||
bytes allocated for clauses, plus
|
||||
@var{Index Size}, the number of bytes spent in the indexing code. The
|
||||
indexing code is divided into a main tree, @var{Tree Index
|
||||
Size}, table that cache clauses for future expansion of the index
|
||||
indexing code is divided into a main tree, @var{Tree Index Size}, table that cache clauses for future expansion of the index
|
||||
tree, @var{Expansion Nodes Size}, and and
|
||||
tables such as hash tables that select according to value, @var{Index Switch Size}.
|
||||
|
||||
@ -5902,7 +5927,6 @@ YAP is booted with the @code{-q} or @code{-L} flag.
|
||||
consulting files. If @code{false} disable printing these messages. It
|
||||
is @code{normal} by default except if YAP is booted with the @code{-L}
|
||||
flag.
|
||||
.
|
||||
|
||||
@item version
|
||||
@findex version (yap_flag/2 option)
|
||||
@ -6058,7 +6082,7 @@ filed are ignored.
|
||||
Current source module.
|
||||
|
||||
@item source (prolog_load_context/2 option)
|
||||
@findex file_prolog_load_context/2 option
|
||||
@findex source_prolog_load_context/2 option
|
||||
@*
|
||||
Full name for the file currently being read in, which may be consulted,
|
||||
reconsulted, or included.
|
||||
|
@ -51,14 +51,14 @@ PROJECT_BRIEF =
|
||||
# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
|
||||
# to the output directory.
|
||||
|
||||
PROJECT_LOGO = ../misc/icons/yap_96x96x32.png
|
||||
PROJECT_LOGO = misc/icons/yap_96x96x32.png
|
||||
|
||||
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
|
||||
# into which the generated documentation will be written. If a relative path is
|
||||
# entered, it will be relative to the location where doxygen was started. If
|
||||
# left blank the current directory will be used.
|
||||
|
||||
OUTPUT_DIRECTORY = ../../doxout
|
||||
OUTPUT_DIRECTORY = doxout
|
||||
|
||||
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create 4096 sub-
|
||||
# directories (in 2 levels) under the output directory of each output format and
|
||||
@ -68,7 +68,7 @@ OUTPUT_DIRECTORY = ../../doxout
|
||||
# performance problems for the file system.
|
||||
# The default value is: NO.
|
||||
|
||||
CREATE_SUBDIRS = NO
|
||||
CREATE_SUBDIRS = YES
|
||||
|
||||
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
|
||||
# documentation generated by doxygen is written. Doxygen will use this
|
||||
@ -230,7 +230,12 @@ TAB_SIZE = 4
|
||||
# "Side Effects:". You can put \n's in the value part of an alias to insert
|
||||
# newlines.
|
||||
|
||||
ALIASES =
|
||||
ALIASES ="predicate=@brief" \
|
||||
"doxygen=\if english" \
|
||||
"endenglish=\endif" \
|
||||
"dutch=\if dutch" \
|
||||
"enddutch=\endif"
|
||||
|
||||
|
||||
# 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"
|
||||
@ -244,7 +249,9 @@ TCL_SUBST =
|
||||
# members will be omitted, etc.
|
||||
# The default value is: NO.
|
||||
|
||||
OPTIMIZE_OUTPUT_FOR_C = YES
|
||||
OPTIMIZE_OUTPUT_FOR_C = NO
|
||||
|
||||
OPTIMIZE_OUTPUT_FOR_PROLOG = YES
|
||||
|
||||
# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
|
||||
# Python sources only. Doxygen will then generate output that is more tailored
|
||||
@ -280,7 +287,7 @@ OPTIMIZE_OUTPUT_VHDL = NO
|
||||
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
|
||||
# the files are not read by doxygen.
|
||||
|
||||
EXTENSION_MAPPING = md
|
||||
EXTENSION_MAPPING = md pl=Prolog
|
||||
|
||||
# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
|
||||
# according to the Markdown format, which allows for more readable
|
||||
@ -682,7 +689,7 @@ LAYOUT_FILE =
|
||||
# search path. Do not use file names with spaces, bibtex cannot handle them. See
|
||||
# also \cite for info how to create references.
|
||||
|
||||
CITE_BIB_FILES = yap.bib
|
||||
CITE_BIB_FILES = docs/yap.bib
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to warning and progress messages
|
||||
@ -753,7 +760,7 @@ WARN_LOGFILE =
|
||||
# spaces.
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = yap.md
|
||||
INPUT = docs/yap.md pl/absf.yap C/cmppreds.c C/eval.c H/eval.h C/arith0.c C/arith1.c C/arith2.c pl/arithpreds.yap
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
@ -788,6 +795,7 @@ FILE_PATTERNS = *.c \
|
||||
*.ddl \
|
||||
*.odl \
|
||||
*.h \
|
||||
*.h.in \
|
||||
*.hh \
|
||||
*.hxx \
|
||||
*.hpp \
|
||||
@ -814,7 +822,9 @@ FILE_PATTERNS = *.c \
|
||||
*.ucf \
|
||||
*.qsf \
|
||||
*.as \
|
||||
*.js
|
||||
*.js \
|
||||
*.pl \
|
||||
*.yap
|
||||
|
||||
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
||||
# be searched for input files as well.
|
||||
@ -930,7 +940,7 @@ FILTER_SOURCE_PATTERNS =
|
||||
# (index.html). This can be useful if you have a project on for instance GitHub
|
||||
# and want to reuse the introduction page also for the doxygen output.
|
||||
|
||||
USE_MDFILE_AS_MAINPAGE =
|
||||
USE_MDFILE_AS_MAINPAGE = NO
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Configuration options related to source browsing
|
||||
@ -949,7 +959,7 @@ SOURCE_BROWSER = YES
|
||||
# classes and enums directly into the documentation.
|
||||
# The default value is: NO.
|
||||
|
||||
INLINE_SOURCES = NO
|
||||
INLINE_SOURCES = YES
|
||||
|
||||
# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
|
||||
# special comment blocks from generated source code fragments. Normal C, C++ and
|
||||
@ -1422,7 +1432,7 @@ DISABLE_INDEX = NO
|
||||
# The default value is: NO.
|
||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
||||
|
||||
GENERATE_TREEVIEW = NO
|
||||
GENERATE_TREEVIEW = YES
|
||||
|
||||
# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
|
||||
# doxygen will group on one line in the generated HTML documentation.
|
||||
|
@ -198,6 +198,15 @@ files specified by @var{F} into the file being currently consulted.
|
||||
@end table
|
||||
|
||||
@node Setting the Compiler, Conditional Compilation, Compiling, Loading Programs
|
||||
|
||||
@section Looking for Files
|
||||
|
||||
@ifplaintext
|
||||
@ref abs_file_name
|
||||
@end ifplaintext
|
||||
|
||||
|
||||
|
||||
@section Changing the Compiler's Behavior
|
||||
|
||||
This section presents a set of built-ins predicates designed to set the
|
||||
@ -304,6 +313,8 @@ Puts YAP in state @var{N} (@code{on} or @code{off}) and unify
|
||||
@code{do_not_compile_expressions}. This predicate was kept to maintain
|
||||
compatibility with C-Prolog.
|
||||
|
||||
@texinfo
|
||||
|
||||
@item path(-@var{D})
|
||||
@findex path/1
|
||||
@snindex path/1
|
||||
@ -333,6 +344,8 @@ YAP, specified by @var{N}. @var{N} must be either of
|
||||
@cnindex remove_from_path/1
|
||||
Remove @var{D} from YAP's directory search path.
|
||||
|
||||
@end texinfo
|
||||
|
||||
@item style_check(+@var{X})
|
||||
@findex style_check/1
|
||||
@snindex style_check/1
|
||||
@ -414,6 +427,8 @@ Similar to @code{initialization/1}, but allows for specifying when
|
||||
restoring a state (not implemented yet).
|
||||
@end table
|
||||
|
||||
@texinfo
|
||||
|
||||
@item library_directory(+@var{D})
|
||||
@findex library_directory/1
|
||||
@snindex library_directory/1
|
||||
@ -428,7 +443,7 @@ directories are the places where files specified in the form
|
||||
@findex file_search_path/2
|
||||
@syindex file_search_path/2
|
||||
@cnindex file_search_path/2
|
||||
Allows writing file names as compound terms. The @var{NAME} and
|
||||
Allows writing file names as compound terms. The @var{NAME} and
|
||||
@var{DIRECTORY} must be atoms. The predicate may generate multiple
|
||||
solutions. The predicate is originally defined as follows:
|
||||
|
||||
@ -450,6 +465,8 @@ Thus, @code{[library(A)]} will search for a file using
|
||||
Unify @var{FullPath} with the absolute path YAP would use to consult
|
||||
file @var{Name}.
|
||||
|
||||
@end texinfo
|
||||
|
||||
@item prolog_to_os_filename(+@var{PrologPath},-@var{OsPath})
|
||||
@findex prolog_to_os_filename/2
|
||||
@snindex prolog_to_os_filename/2
|
||||
|
94
docs/swi.tex
94
docs/swi.tex
@ -7,17 +7,17 @@ default in YAP. This support is loaded with the
|
||||
@table @code
|
||||
|
||||
@item append(?@var{List1},?@var{List2},?@var{List3})
|
||||
@findex append/3
|
||||
@snindex append/3
|
||||
@cnindex append/3
|
||||
@findex swi_append/3
|
||||
@snindex swi_append/3
|
||||
@cnindex swi_append/3
|
||||
Succeeds when @var{List3} unifies with the concatenation of @var{List1}
|
||||
and @var{List2}. The predicate can be used with any instantiation
|
||||
pattern (even three variables).
|
||||
|
||||
@item between(+@var{Low},+@var{High},?@var{Value})
|
||||
@findex between/3
|
||||
@snindex between/3
|
||||
@cnindex between/3
|
||||
@findex swi_between/3
|
||||
@snindex swi_between/3
|
||||
@cnindex swi_between/3
|
||||
|
||||
@var{Low} and @var{High} are integers, @var{High} less or equal than
|
||||
@var{Low}. If @var{Value} is an integer, @var{Low} less or equal than
|
||||
@ -67,9 +67,9 @@ L = [gnu, gnat]
|
||||
@end example
|
||||
|
||||
@item nth1(+@var{Index},?@var{List},?@var{Elem})
|
||||
@findex nth1/3
|
||||
@snindex nth1/3
|
||||
@cnindex nth1/3
|
||||
@findex swi_nth1/3
|
||||
@snindex swi_nth1/3
|
||||
@cnindex swi_nth1/3
|
||||
Succeeds when the @var{Index}-th element of @var{List} unifies with
|
||||
@var{Elem}. Counting starts at 1.
|
||||
|
||||
@ -79,18 +79,18 @@ passed to @code{shell/[0-2]} and can be requested using @code{getenv/2}.
|
||||
They also influence @code{expand_file_name/2}.
|
||||
|
||||
@item setenv(+@var{Name},+@var{Value})
|
||||
@findex setenv/2
|
||||
@snindex setenv/2
|
||||
@cnindex setenv/2
|
||||
@findex swi_setenv/2
|
||||
@snindex swi_setenv/2
|
||||
@cnindex swi_setenv/2
|
||||
Set environment variable. @var{Name} and @var{Value} should be
|
||||
instantiated to atoms or integers. The environment variable will be
|
||||
passed to @code{shell/[0-2]} and can be requested using @code{getenv/2}.
|
||||
They also influence @code{expand_file_name/2}.
|
||||
|
||||
@item term_to_atom(?@var{Term},?@var{Atom})
|
||||
@findex term_to_atom/2
|
||||
@snindex term_to_atom/2
|
||||
@cnindex term_to_atom/2
|
||||
@findex swi_term_to_atom/2
|
||||
@snindex swi_term_to_atom/2
|
||||
@cnindex swi_term_to_atom/2
|
||||
Succeeds if @var{Atom} describes a term that unifies with @var{Term}. When
|
||||
@var{Atom} is instantiated @var{Atom} is converted and then unified with
|
||||
@var{Term}. If @var{Atom} has no valid syntax, a @code{syntax_error}
|
||||
@ -98,9 +98,9 @@ exception is raised. Otherwise @var{Term} is ``written'' on @var{Atom}
|
||||
using @code{write/1}.
|
||||
|
||||
@item working_directory(-@var{Old},+@var{New})
|
||||
@findex working_directory/2
|
||||
@snindex working_directory/2
|
||||
@cnindex working_directory/2
|
||||
@findex swi_working_directory/2
|
||||
@snindex swi_working_directory/2
|
||||
@cnindex swi_working_directory/2
|
||||
|
||||
Unify @var{Old} with an absolute path to the current working directory
|
||||
and change working directory to @var{New}. Use the pattern
|
||||
@ -136,26 +136,26 @@ we will phrase this as ``@var{Predicate} is applied on ...''
|
||||
@table @code
|
||||
|
||||
@item maplist(+@var{Pred},+@var{List})
|
||||
@findex maplist/2
|
||||
@snindex maplist/2
|
||||
@cnindex maplist/2
|
||||
@findex swi_maplist/2
|
||||
@snindex swi_maplist/2
|
||||
@cnindex swi_maplist/2
|
||||
@var{Pred} is applied successively on each element of @var{List} until
|
||||
the end of the list or @var{Pred} fails. In the latter case
|
||||
@code{maplist/2} fails.
|
||||
|
||||
@item maplist(+@var{Pred},+@var{List1},+@var{List2})
|
||||
@findex maplist/3
|
||||
@snindex maplist/3
|
||||
@cnindex maplist/3
|
||||
@findex swi_maplist/3
|
||||
@snindex swi_maplist/3
|
||||
@cnindex swi_maplist/3
|
||||
Apply @var{Pred} on all successive pairs of elements from
|
||||
@var{List1} and
|
||||
@var{List2}. Fails if @var{Pred} can not be applied to a
|
||||
pair. See the example above.
|
||||
|
||||
@item maplist(+@var{Pred},+@var{List1},+@var{List2},+@var{List4})
|
||||
@findex maplist/4
|
||||
@snindex maplist/4
|
||||
@cnindex maplist/4
|
||||
@findex swi_maplist/4
|
||||
@snindex swi_maplist/4
|
||||
@cnindex swi_maplist/4
|
||||
Apply @var{Pred} on all successive triples of elements from @var{List1},
|
||||
@var{List2} and @var{List3}. Fails if @var{Pred} can not be applied to a
|
||||
triple. See the example above.
|
||||
@ -174,9 +174,10 @@ triple. See the example above.
|
||||
|
||||
@table @code
|
||||
@item forall(+@var{Cond},+@var{Action})
|
||||
@findex forall/2
|
||||
@snindex forall/2
|
||||
@cnindex forall/2
|
||||
@findex swi_forall/2
|
||||
@snindex swi_forall/2
|
||||
@snindex swi_forall/2
|
||||
@cnindex swi_forall/2
|
||||
|
||||
For all alternative bindings of @var{Cond} @var{Action} can be proven.
|
||||
The next example verifies that all arithmetic statements in the list
|
||||
@ -233,9 +234,9 @@ threads that are created @emph{after} the registration.
|
||||
|
||||
@table @code
|
||||
@item b_setval(+@var{Name},+@var{Value})
|
||||
@findex b_setval/2
|
||||
@snindex b_setval/2
|
||||
@cnindex b_setval/2
|
||||
@findex swi_b_setval/2
|
||||
@snindex swi_b_setval/2
|
||||
@cnindex swi_b_setval/2
|
||||
Associate the term @var{Value} with the atom @var{Name} or replaces
|
||||
the currently associated value with @var{Value}. If @var{Name} does
|
||||
not refer to an existing global variable a variable with initial value
|
||||
@ -243,31 +244,28 @@ not refer to an existing global variable a variable with initial value
|
||||
assignment is reversed.
|
||||
|
||||
@item b_getval(+@var{Name},-@var{Value})
|
||||
@findex b_getval/2
|
||||
@snindex b_getval/2
|
||||
@cnindex b_getval/2
|
||||
@findex swi_b_getval/2
|
||||
@snindex swi_b_getval/2
|
||||
@cnindex swi_b_getval/2
|
||||
Get the value associated with the global variable @var{Name} and unify
|
||||
it with @var{Value}. Note that this unification may further instantiate
|
||||
the value of the global variable. If this is undesirable the normal
|
||||
precautions (double negation or @code{copy_term/2}) must be taken. The
|
||||
@code{b_getval/2} predicate generates errors if @var{Name} is not an atom or
|
||||
the requested variable does not exist.
|
||||
@end table
|
||||
|
||||
@table @code
|
||||
|
||||
@item nb_setval(+@var{Name},+@var{Value})
|
||||
@findex nb_setval/2
|
||||
@snindex nb_setval/2
|
||||
@cnindex nb_setval/2
|
||||
@findex swi_nb_setval/2
|
||||
@snindex swi_nb_setval/2
|
||||
@cnindex swi_nb_setval/2
|
||||
Associates a copy of @var{Value} created with @code{duplicate_term/2}
|
||||
with the atom @var{Name}. Note that this can be used to set an
|
||||
initial value other than @code{[]} prior to backtrackable assignment.
|
||||
|
||||
@item nb_getval(+@var{Name},-@var{Value})
|
||||
@findex nb_getval/2
|
||||
@snindex nb_getval/2
|
||||
@cnindex nb_getval/2
|
||||
@findex swi_nb_getval/2
|
||||
@snindex swi_nb_getval/2
|
||||
@cnindex swi_nb_getval/2
|
||||
The @code{nb_getval/2} predicate is a synonym for b_getval/2, introduced for
|
||||
compatibility and symmetry. As most scenarios will use a particular
|
||||
global variable either using non-backtrackable or backtrackable
|
||||
@ -297,9 +295,9 @@ variable is used non-backtrackable.
|
||||
@c \end{code}
|
||||
|
||||
@item nb_current(?@var{Name},?@var{Value})
|
||||
@findex nb_current/2
|
||||
@snindex nb_current/2
|
||||
@cnindex nb_current/2
|
||||
@findex swi_nb_current/2
|
||||
@snindex swi_nb_current/2
|
||||
@cnindex swi_nb_current/2
|
||||
Enumerate all defined variables with their value. The order of
|
||||
enumeration is undefined.
|
||||
|
||||
|
@ -34,7 +34,6 @@ scan_file( Inp ) :-
|
||||
repeat,
|
||||
line_count( S, Lines ),
|
||||
read_line_to_string(S, Line0),
|
||||
%( Lines = 416 %string(Line0),sub_string( Line0,_,_,_, "\secref{unicodesyntax}") -> trace ; true ),
|
||||
assert_static( source( Inp, Lines, Line0 ) ),
|
||||
( Line0 == end_of_file ->
|
||||
!,
|
||||
@ -131,7 +130,9 @@ out( _S ) :-
|
||||
nb_setval( min, 0 ),
|
||||
fail.
|
||||
out( S ) :-
|
||||
line( F, Pos, Line),
|
||||
line( F, Pos, Line0),
|
||||
%( Pos = 5770 -> trace ; true ),
|
||||
jmp_blanks( Line0, Line),
|
||||
b_setval( line, F:Pos:Line ),
|
||||
process( Line , NewLine, F:Pos),
|
||||
offset( N ),
|
||||
@ -141,8 +142,8 @@ out( S ) :-
|
||||
;
|
||||
NewLine == ""
|
||||
->
|
||||
% nb_getval( old_line, OldLine ),
|
||||
% OldLine \= "",
|
||||
nb_getval( old_line, OldLine ),
|
||||
OldLine \= "",
|
||||
format(string(SN), '~n', [])
|
||||
;
|
||||
NewLine == force
|
||||
@ -185,6 +186,9 @@ singleton_line(L) :- string_concat("@itemize",_R,L), !.
|
||||
singleton_line(L) :- string_concat("@enumerate",_R,L), !.
|
||||
singleton_line(L) :- string_concat("@table",_R,L), !.
|
||||
singleton_line(L) :- string_concat("@example",_R,L), !, assert( singletons ).
|
||||
singleton_line(L) :- string_concat("@ifplaintext",_R,L), !, assert( singletons ).
|
||||
singleton_line(L) :- string_concat("@pl_example",_R,L), !, assert( singletons ).
|
||||
singleton_line(L) :- string_concat("@c_example",_R,L), !, assert( singletons ).
|
||||
singleton_line(L) :- string_concat("@simpleexample",_R,L), !, assert( singletons ).
|
||||
singleton_line(L) :- string_concat("@end",R,L), !,
|
||||
( sub_string(R, _, _, _, "example") -> retract( singletons ) ; true ).
|
||||
@ -200,16 +204,20 @@ process( Line , S, F:Pos ) :-
|
||||
(
|
||||
first_word(Line, "@end", Rest)
|
||||
->
|
||||
first_word(Rest, Env1, _Rest2),
|
||||
(
|
||||
( Env1 == "example" ; Env1 == "smallexample" )
|
||||
first_word(Rest, Env1, _Rest2),
|
||||
sub_string( Env1, _, _, 0, "example" )
|
||||
->
|
||||
( S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
|
||||
pop( skip, verbatim ), fail
|
||||
)
|
||||
% fail in other ends
|
||||
% ;
|
||||
% Env1 = "cartouche"
|
||||
;
|
||||
first_word(Rest, Env1, _Rest2),
|
||||
sub_string( Env1, _, _, 0, "plaintext" )
|
||||
->
|
||||
( S = "" ;
|
||||
pop( skip, verbatim ), fail
|
||||
)
|
||||
)
|
||||
;
|
||||
first_word(Line, "@cartouche", Rest)
|
||||
@ -224,8 +232,12 @@ process( Line , "", _Pos ) :-
|
||||
first_word(Line, Word, Rest),
|
||||
Word == "@end",
|
||||
first_word(Rest, Word2, _Rest),
|
||||
W2 = Word2,
|
||||
pop( skip, W2 ).
|
||||
( W2 = Word2
|
||||
->
|
||||
pop( skip, W2 )
|
||||
;
|
||||
true
|
||||
).
|
||||
% command: flush and continue
|
||||
process( Command , NewLine , Pos) :-
|
||||
do_buffer(Command, NewLine, Pos ).
|
||||
@ -254,36 +266,49 @@ command( Line, Word, Rest ) :-
|
||||
clause( process( Word, _, _, _, _ ), _),
|
||||
!.
|
||||
|
||||
process("@item", _Line, _Rest, NewLine , _FilePos) :-
|
||||
speek( list, it(_Env, _Item, _Pos, Numb)),
|
||||
Numb > 1,
|
||||
NewLine = "</li>".
|
||||
process("@item", Line, Rest, NewLine , FilePos) :-
|
||||
pop( list, it(Env, Item, Pos, Numb)), !,
|
||||
NNumb is Numb+1,
|
||||
run( Text, Rest ),
|
||||
jmp_blanks( Rest, First ),
|
||||
item_type(Item, Numb, Marker ),
|
||||
jmp_blanks( Text, First ),
|
||||
Pos1 is Pos,
|
||||
% item_type(Item, Numb, Marker ),
|
||||
Marker = "",
|
||||
(
|
||||
Env = "table",
|
||||
Env = "@table",
|
||||
atom_string( A, Line ),
|
||||
pred( _Pred, Key, A, FilePos )
|
||||
->
|
||||
push( list, it(Env, Item, Pos, NNumb) ),
|
||||
(
|
||||
% sendout the comand
|
||||
format(string(NewLine), '~t~s ~*|~s @anchor ~a', [Marker, Pos, First, Key]),
|
||||
format(string(NewLine), '~t~s ~*+<li>~s @anchor ~a', [Marker, Pos1, First, Key]),
|
||||
push( indent, done )
|
||||
;
|
||||
NewLine = force
|
||||
)
|
||||
;
|
||||
format(string(NewLine), '~t~s ~*|~s', [ Marker, Pos, First]),
|
||||
format(string(NewLine), '~t~s ~*+<li>~s', [ Marker, Pos, First]),
|
||||
push( list, it(Env, Item, Pos, NNumb) ),
|
||||
push( indent, done )
|
||||
).
|
||||
). %, writeln(+FilePos:Line), listing(stack).
|
||||
process("@end", _Line, _Rest, "</li>" , _Pos) :-
|
||||
once( speek(list,it(_Env,_,_LL,_)) ).
|
||||
process("@end", _Line, Rest, NewLine , _Pos) :-
|
||||
speek(list,it(Env,_,_LL,_)),
|
||||
( Env = "@enumerate" ->
|
||||
NewLine = "</ol>"
|
||||
;
|
||||
NewLine = "</ul>"
|
||||
),
|
||||
sub_string( Env, 1, _, 0, Env1 ),
|
||||
sub_string( Rest, _, _, _, Env1), !, % check
|
||||
pop( list, it(Env, _, _, _) ),
|
||||
NewLine = "".
|
||||
% writeln(_Pos:_Line), listing(stack),
|
||||
pop( list, it(Env, _, _, _) ).
|
||||
process("@end", Line, _Rest, NewLine , _Pos) :-
|
||||
sub_string(Line, _, _, 0, "ifnottex"), !, % check
|
||||
NewLine = "\\endhtmlonly".
|
||||
@ -304,7 +329,11 @@ process("@end", Line, _Rest, NewLine , _Pos) :-
|
||||
process("@author", _Line, Rest, NewLine , _Pos) :- !,
|
||||
jmp_blanks( Rest, Firs ),
|
||||
format( string( NewLine), '\\author ~s', [ Firs ] ).
|
||||
process("@*", _Line, _Rest, ¨¨ , _Pos) :- !.
|
||||
process("@*", _Line, _Rest, "" , _Pos).
|
||||
process("@*", _Line, Rest, Line , _Pos) :-
|
||||
!,
|
||||
jmp_blanks( Rest, Firs ),
|
||||
run( Line, Firs ).
|
||||
process("@c", _Line, Rest, NewLine , _Pos) :- !,
|
||||
gen_comment( Rest, NewLine ).
|
||||
process("@comment", _Line, Rest, NewLine , _Pos) :- !,
|
||||
@ -320,7 +349,8 @@ process("@chapter", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
run( Title, Firs ),
|
||||
nb_setval( level, 1 ),
|
||||
title_from_words(Firs, Id, _Pos),
|
||||
format(string(NewLine), '@section ~s ~s', [Id,Title]).
|
||||
title( '@chapter', _, TitleDox ),
|
||||
format(string(NewLine), '~a ~s ~s', [TitleDox, Id,Title]).
|
||||
% ( format( string(NewLine), '~s', [Title] ) ; NewLine = "======" ).
|
||||
process("@cindex", _Line, _Rest, no , _Pos) :- !.
|
||||
process("@caindex", _Line, _Rest, no, _Pos ) :- !.
|
||||
@ -329,6 +359,9 @@ process("@defindex", Line, _Rest, NewLine , _Pos) :- !,
|
||||
process("@direntry", Line, _Rest, NewLine, _Pos ) :- !,
|
||||
gen_comment( Line, NewLine ),
|
||||
push(skip, "direntry" ).
|
||||
process("@texinfo", Line, _Rest, NewLine, _Pos ) :- !,
|
||||
gen_comment( Line, NewLine ),
|
||||
push(skip, "texinfo" ).
|
||||
process("@documentencoding", _Line, _Rest, "" , _Pos) :- !.
|
||||
% jmp_blanks( Rest, NewString ),
|
||||
% format( string( NewLine), '<meta charset="~s">', [ NewString ] ).
|
||||
@ -340,7 +373,16 @@ process("@enumerate", _Line, _Rest, NewLine , _Pos) :-
|
||||
process("@example", _Line, _Rest, "" , _Pos).
|
||||
process("@example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !,
|
||||
push( skip, verbatim).
|
||||
process("@ifplaintext", _Line, _Rest, "" , _Pos) :- !,
|
||||
push( skip, verbatim).
|
||||
process("@pl_example", _Line, _Rest, "" , _Pos).
|
||||
process("@pl_example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.prolog}" , _Pos) :- !,
|
||||
push( skip, verbatim).
|
||||
process("@c_example", _Line, _Rest, "" , _Pos).
|
||||
process("@c_example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.c}" , _Pos) :- !,
|
||||
push( skip, verbatim).
|
||||
process("@format", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@alias", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@dircategory", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@smallexample", _Line, _Rest, "" , _Pos).
|
||||
process("@smallexample", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !,
|
||||
@ -373,8 +415,9 @@ process("@section", _Line, Rest, NewLine, Pos ) :- !,
|
||||
run( NewTitle, Title ),
|
||||
nb_setval( level, 2 ),
|
||||
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||
title( '@section', _, TitleDox ),
|
||||
title_from_words(NewTitle, Id, Pos),
|
||||
format(string(NewLine), '@subsection ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '~a ~s ~s', [TitleDox,Id,NewTitle]).
|
||||
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||
process("@appendix", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
jmp_blanks( Rest, Title ),
|
||||
@ -384,8 +427,9 @@ process("@subsection", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
jmp_blanks( Rest, Title ),
|
||||
run( NewTitle, Title ),
|
||||
nb_setval( level, 3 ),
|
||||
title( '@subsection', _, TitleDox ),
|
||||
title_from_words(NewTitle, Id, _Pos),
|
||||
format(string(NewLine), '@subsubsection ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '~a ~s ~s', [TitleDox,Id,NewTitle]).
|
||||
% format(string(NewLine), '## ~s ##', [NewTitle]).
|
||||
process("@unnumberedsubsubsec", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
nb_setval( level, 4 ),
|
||||
@ -394,8 +438,9 @@ process("@subsubsection", _Line, Rest, NewLine, _Pos ) :- !,
|
||||
nb_setval( level, 4 ),
|
||||
jmp_blanks( Rest, Title ),
|
||||
run( NewTitle, Title ),
|
||||
title( '@subsubsection', _, TitleDox ),
|
||||
title_from_words(NewTitle, Id, _Pos),
|
||||
format(string(NewLine), '@paragraph ~s ~s', [Id,NewTitle]).
|
||||
format(string(NewLine), '~a ~s', [TitleDox,Id,NewTitle]).
|
||||
% format(string(NewLine), '### ~s ###', [NewTitle]).
|
||||
process("@set", _Line, Rest, NewLine , _Pos) :- !,
|
||||
first_word( Rest, V, SecC),
|
||||
@ -416,16 +461,7 @@ process("@setchapternewpage", Line, _Rest, NewLine, _Pos ) :- !,
|
||||
gen_comment( Line, NewLine ).
|
||||
process("@setfilename", Line, _Rest, NewLine, _Pos ) :- !,
|
||||
gen_comment( Line, NewLine ).
|
||||
process("@settitle", _Line, Rest, NewLine , _Pos) :- !,
|
||||
jmp_blanks( Rest, Title ),
|
||||
( format(string(NewLine), '~s {#mainpage}', [Title]) ; NewLine = "=================="; NewLine = "" ;
|
||||
NewLine = "";
|
||||
NewLine = "[TOC]";
|
||||
NewLine = "";
|
||||
NewLine = "@secreflist" ;
|
||||
NewLine = "";
|
||||
NewLine = "@endsecreflist"
|
||||
).
|
||||
process("@settitle", _Line, _Rest, "" , _Pos) :- !.
|
||||
process("@subtitle", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@include", _Line, _Rest, "", _Pos ) :- !.
|
||||
process("@table", _Line, Rest, NewLine , _Pos) :- !,
|
||||
@ -461,21 +497,25 @@ get_second( Rest, Title ) :-
|
||||
% clear the buffer first.
|
||||
%
|
||||
list( Env, Line, New, _Pos) :-
|
||||
writeln(_Pos),
|
||||
first_word( Line, V, Rest),
|
||||
jmp_blanks( Rest, End ),
|
||||
(
|
||||
speek( list, it(_, _,Pos, _) ) ->
|
||||
Pos1 is Pos + 6
|
||||
speek( list, it(_, _, _Pos, _) ) ->
|
||||
Pos1 is 0 % Pos + 4
|
||||
;
|
||||
Pos1 = 6
|
||||
Pos1 = 0 %4
|
||||
),
|
||||
push( list, it( Env, V, Pos1, 1 ) ),
|
||||
% b_getval( pos, _Pos ),
|
||||
% writeln(add:_Pos:Env:Pos1:End),
|
||||
% listing(stack),
|
||||
run( New, End).
|
||||
|
||||
list( Env, _Line, NewLine, _Pos) :-
|
||||
( Env = "@enumerate" ->
|
||||
NewLine = "<ol>"
|
||||
;
|
||||
NewLine = "<ul>"
|
||||
).
|
||||
|
||||
item_type("@bullet", _, "-" ).
|
||||
item_type("@code", _, "-" ).
|
||||
@ -521,9 +561,11 @@ from_word( Line, Id ) :-
|
||||
simplify( C1, C0, []),
|
||||
string_codes( Id, C1 ).
|
||||
|
||||
simplify( [0'_|L]) --> " ", !,
|
||||
simplify( [0'_|L]) --> " ", !, %'
|
||||
simplify(L).
|
||||
simplify( [0'a,0'A|L]) --> "@", !,
|
||||
simplify( [0's,0'T|L]) --> "*", !, %'
|
||||
simplify(L).
|
||||
simplify( [0'a,0'A|L]) --> "@", !,
|
||||
simplify(L).
|
||||
simplify( [0'b,0'A|L]) --> "'", !,
|
||||
simplify(L).
|
||||
@ -637,7 +679,7 @@ pop(Type, Val) :-
|
||||
stack(T, V), !,
|
||||
T = Type,
|
||||
V = Val,
|
||||
retract(stack(T,V)).
|
||||
once( retract(stack(T,V)) ).
|
||||
|
||||
push(Type, Val) :-
|
||||
asserta(stack(Type,Val)).
|
||||
@ -706,11 +748,17 @@ run( L) --> "@value{", !,
|
||||
run(R).
|
||||
run( L) --> "@pxref{", !,
|
||||
argument(AL, 0'{, 0'}),
|
||||
{ format(codes(L, R), '`see ~s`', [AL] ) }, %'
|
||||
{
|
||||
string_codes(S, AL),
|
||||
from_word(S, Id),
|
||||
format(codes(L, R), ' (see [~s](@ref ~s))', [AL,Id] ) }, %' %
|
||||
run(R).
|
||||
run( L) --> "@ref{", !,
|
||||
argument(AL, 0'{, 0'}),
|
||||
{ format(codes(L, R), '[~s](@ref ~s)', [AL,AL] ) }, %'
|
||||
{
|
||||
string_codes(S, AL),
|
||||
from_word(S, Id),
|
||||
format(codes(L, R), '[~s](@ref ~s)', [AL,Id] ) }, %'
|
||||
run(R).
|
||||
run( L) --> "@strong{", !,
|
||||
argument(AL, 0'{, 0'}),
|
||||
@ -808,11 +856,9 @@ argument(L, _C0, _C, L, []) :-
|
||||
format(user_error, 'Line ~w :-~n argument ~c~s~c does not close in same line.~n', [Line, _C0, L, _C]).
|
||||
|
||||
argument0([], 0, _, C ) --> [C], !.
|
||||
%:- start_low_level_trace.
|
||||
argument0([C|L], I0, C0, C ) --> [C], !,
|
||||
{ I0 > 0, I is I0-1 },
|
||||
argument0( L, I, C0, C).
|
||||
%:- stop_low_level_trace.
|
||||
argument0([C0|L], I0, C0, C ) --> [C0], !,
|
||||
{ I is I0+1 },
|
||||
argument0( L, I, C0, C).
|
||||
@ -854,11 +900,18 @@ id(X) :-
|
||||
X1 is X+100,
|
||||
assert(i(X1)).
|
||||
|
||||
title(1, page).
|
||||
title(2, section).
|
||||
title(3, subsection).
|
||||
title(4, subsubsection).
|
||||
title(5, paragraph).
|
||||
title(6, paragraph).
|
||||
title(TexTitle, Level, DoxTitle) :-
|
||||
title( Level, TexTitle),
|
||||
% Level1 is Level + 1,
|
||||
title( Level, DoxTitle ), !.
|
||||
|
||||
title(1, '@page' ).
|
||||
title(1, '@chapter' ).
|
||||
title(2, '@section' ).
|
||||
title(3, '@subsection' ).
|
||||
title(4, '@subsubsection' ).
|
||||
title(5, '@paragraph' ).
|
||||
title(6, '@paragraph' ).
|
||||
|
||||
%:- spy title_from_words.
|
||||
|
504
docs/yap.tex
504
docs/yap.tex
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
Subproject commit d5c70de04a6fce6be71a9086d0164dd0b0c9d9d4
|
||||
Subproject commit 0f77a1e1b90b36bddb1844712380f4f3858123b7
|
@ -1 +1 @@
|
||||
Subproject commit abd65ae6486993e04dfa883163efdad3bab789ab
|
||||
Subproject commit a8a43aa09892c4b7018dc053d8e7653e2f648107
|
240
pl/absf.yap
240
pl/absf.yap
@ -4,18 +4,27 @@
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: consult.yap *
|
||||
* Last rev: 8/2/88 *
|
||||
* mods: *
|
||||
* comments: Consulting Files in YAP *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2014 *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
:- system_module( '$_absf', [absolute_file_name/2,
|
||||
/**
|
||||
@file absf.yap
|
||||
|
||||
@defgroup abs_file_name File Name Resolution
|
||||
|
||||
Support for file name resolution through absolute_file_name/3 and
|
||||
friends. These utility built-ins describe a list of directories that
|
||||
are used by load_files/2 to search. They include pre-compiled paths
|
||||
plus user-defined directories, directories based on environment
|
||||
variables and registry information to search for files.
|
||||
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
|
||||
:- system_module( absolute_file_name, [absolute_file_name/2,
|
||||
absolute_file_name/3,
|
||||
add_to_path/1,
|
||||
add_to_path/2,
|
||||
@ -30,20 +39,89 @@
|
||||
:- use_system_module( '$_lists', [member/2]).
|
||||
|
||||
/**
|
||||
*
|
||||
* @defgroup AbsoluteFileName File Name Resolution
|
||||
*
|
||||
* @subsection sub:AbsFileName File Name Resolution in Prolog
|
||||
absolute_file_name(+File:atom, +Options:list, +Path:atom) is nondet
|
||||
absolute_file_name(-File:atom, +Path:atom, +Options:list) is nondet
|
||||
|
||||
Support for file name resolution through absolute_file_name/3 and
|
||||
friends. These utility built-ins are used by load_files/2 to search
|
||||
in the library directories. They use pre-compiled paths plus
|
||||
environment variables and registry information to search for files.
|
||||
_Options_ is a list of options to guide the conversion:
|
||||
|
||||
- extensions(+ _ListOfExtensions_)
|
||||
|
||||
List of file-extensions to try. Default is `''`. For each
|
||||
extension, absolute_file_name/3 will first add the extension and then
|
||||
verify the conditions imposed by the other options. If the condition
|
||||
fails, the next extension of the list is tried. Extensions may be
|
||||
specified both with dot, as `.ext`, or without, as plain `ext`.
|
||||
|
||||
- relative_to(+ _FileOrDir_ )
|
||||
|
||||
*/
|
||||
Resolve the path relative to the given directory or directory the
|
||||
holding the given file. Without this option, paths are resolved
|
||||
relative to the working directory (see working_directory/2) or,
|
||||
if _Spec_ is atomic and absolute_file_name/3 is executed
|
||||
in a directive, it uses the current source-file as reference.
|
||||
|
||||
- access(+ _Mode_ )
|
||||
|
||||
Imposes the condition access_file( _File_ , _Mode_ ). _Mode_ is one of `read`, `write`, `append`, `exist` or
|
||||
`none` (default).
|
||||
|
||||
See also access_file/2.
|
||||
|
||||
- file_type(+ _Type_ )
|
||||
|
||||
Defines suffixes matching one of several pre-specified type of files. Default mapping is as follows:
|
||||
|
||||
1. `txt` implies `[ '' ]`,
|
||||
|
||||
2. `prolog` implies `['.yap', '.pl', '.prolog', '']`,
|
||||
|
||||
3. `executable` implies `['.so', ',dylib', '.dll']` depending on the Operating system,
|
||||
|
||||
4. `qlf` implies `['.qlf', '']`,
|
||||
|
||||
5. `directory` implies `['']`,
|
||||
|
||||
6. The file-type `source` is an alias for `prolog` designed to support compatibility with SICStus Prolog. See also prolog_file_type/2.
|
||||
|
||||
Notice that this predicate only
|
||||
returns non-directories, unless the option `file_type(directory)` is
|
||||
specified, or unless `access(none)`.
|
||||
|
||||
- file_errors(`fail`/`error`)
|
||||
|
||||
If `error` (default), throw and `existence_error` exception
|
||||
if the file cannot be found. If `fail`, stay silent.
|
||||
|
||||
- solutions(`first`/`all`)
|
||||
|
||||
If `first` (default), the search cannot backtrack. leaves no choice-point.
|
||||
Otherwise a choice-point will be left and backtracking may yield
|
||||
more solutions.
|
||||
|
||||
- expand(`true`/`false`)
|
||||
|
||||
If `true` (default is `false`) and _Spec_ is atomic,
|
||||
call expand_file_name/2 followed by member/2 on _Spec_ before
|
||||
proceeding. This is originally a SWI-Prolog extension.
|
||||
|
||||
Compatibility considerations to common argument-order in ISO as well
|
||||
as SICStus absolute_file_name/3 forced us to be flexible here.
|
||||
If the last argument is a list and the second not, the arguments are
|
||||
swapped, making the call
|
||||
~~~~~~~~~~~prolog
|
||||
absolute_file_name(+ _Spec_ , - _Path_ ,+ _Options_ )
|
||||
~~~~~~~~~~~
|
||||
valid as well.
|
||||
*/
|
||||
|
||||
absolute_file_name(File,TrueFileName,Opts) :- ( var(TrueFileName) ->
|
||||
true ; atom(TrueFileName), TrueFileName \= [] ), !,
|
||||
absolute_file_name(File,Opts,TrueFileName).
|
||||
absolute_file_name(File,Opts,TrueFileName) :-
|
||||
'$absolute_file_name'(File,Opts,TrueFileName,absolute_file_name(File,Opts,TrueFileName)).
|
||||
|
||||
/**
|
||||
@brief absolute_file_name(+<var>Name</var>:atom,+<var>Options</var>:list) is nondet
|
||||
absolute_file_name(+Name:atom,+Path:atom) is nondet
|
||||
|
||||
Converts the given file specification into an absolute path, using default options. See absolute_file_name/3 for details on the options.
|
||||
*/
|
||||
@ -58,79 +136,7 @@ absolute_file_name(File0,File) :-
|
||||
'$absolute_file_name'(F0,[access(read),file_type(source),file_errors(fail),solutions(first),expand(true)],F,G).
|
||||
|
||||
|
||||
/**
|
||||
@brief absolute_file_name(+File:atom, +Options:list, +Path:atom) is nondet
|
||||
@brief absolute_file_name(-File:atom, +Path:atom, +Options:list) is nondet
|
||||
|
||||
<var>Option</var> is a list of options to guide the conversion:
|
||||
|
||||
- extensions(+<var>ListOfExtensions</var>)
|
||||
|
||||
List of file-extensions to try. Default is `''`. For each
|
||||
extension, absolute_file_name/3 will first add the extension and then
|
||||
verify the conditions imposed by the other options. If the condition
|
||||
fails, the next extension of the list is tried. Extensions may be
|
||||
specified both as `.ext` or plain `ext`.
|
||||
|
||||
- relative_to(+<var>FileOrDir</var>)
|
||||
|
||||
Resolve the path relative to the given directory or directory the
|
||||
holding the given file. Without this option, paths are resolved
|
||||
relative to the working directory (see [working_directory/2](@ref working_directory/2)) or,
|
||||
if <var>Spec</var> is atomic and `absolute_file_name/[2,3]` is executed
|
||||
in a directive, it uses the current source-file as reference.
|
||||
|
||||
- access(+<var>Mode</var>)
|
||||
|
||||
Imposes the condition access_file(<var>File</var>, <var>Mode</var>). <var>Mode</var> is one of `read`, `write`, `append`, `exist` or
|
||||
`none` (default).
|
||||
|
||||
See also `access_file/2`.
|
||||
|
||||
- file_type(+<var>Type</var>)
|
||||
|
||||
Defines extensions. Current mapping: `txt` implies `['']`,
|
||||
`prolog` implies `['.yap', '.pl', '.prolog', '']`, `executable`
|
||||
implies `['.so', '']`, `qlf` implies `['.qlf', '']` and
|
||||
`directory` implies `['']`. The file-type `source`
|
||||
is an alias for `prolog` for compatibility to SICStus Prolog.
|
||||
See also `prolog_file_type/2`.
|
||||
|
||||
Notice also that this predicate only
|
||||
returns non-directories, unless the option `file_type(directory)` is
|
||||
specified, or unless `access(none)`.
|
||||
|
||||
- file_errors(`fail`/`error`)
|
||||
|
||||
If `error` (default), throw and `existence_error` exception
|
||||
if the file cannot be found. If `fail`, stay silent.
|
||||
|
||||
- solutions(`first`/`all`)
|
||||
|
||||
If `first` (default), the predicates leaves no choice-point.
|
||||
Otherwise a choice-point will be left and backtracking may yield
|
||||
more solutions.
|
||||
|
||||
- expand(`true`/`false`)
|
||||
|
||||
If `true` (default is `false`) and <var>Spec</var> is atomic,
|
||||
call [expand_file_name/2](@ref expand_file_name2) followed by [member/2](@ref member2) on <var>Spec</var> before
|
||||
proceeding. This is originally a SWI-Prolog extension.
|
||||
|
||||
Compatibility considerations to common argument-order in ISO as well
|
||||
as SICStus absolute_file_name/3 forced us to be flexible here.
|
||||
If the last argument is a list and the 2nd not, the arguments are
|
||||
swapped, making the call `absolute_file_name`(+<var>Spec</var>, -<var>Path</var>,
|
||||
+<var>Options</var>) valid as well.
|
||||
*/
|
||||
|
||||
absolute_file_name(File,TrueFileName,Opts) :-
|
||||
( var(TrueFileName) -> true ; atom(TrueFileName), TrueFileName \= [] ),
|
||||
!,
|
||||
absolute_file_name(File,Opts,TrueFileName).
|
||||
absolute_file_name(File,Opts,TrueFileName) :-
|
||||
'$absolute_file_name'(File,Opts,TrueFileName,absolute_file_name(File,Opts,TrueFileName)).
|
||||
|
||||
'$absolute_file_name'(File, _Opts, _TrueFileName, G) :- var(File), !,
|
||||
'$do_error'(instantiation_error, G).
|
||||
'$absolute_file_name'(File,Opts,TrueFileName, G) :-
|
||||
@ -219,7 +225,7 @@ absolute_file_name(File,Opts,TrueFileName) :-
|
||||
'$do_error'(domain_error(file_errors,T),G).
|
||||
'$check_fn_errors'(T,G) :- !,
|
||||
'$do_error'(type_error(atom,T),G).
|
||||
|
||||
|
||||
'$check_fn_solutions'(V,G) :- var(V), !,
|
||||
'$do_error'(instantiation_error, G).
|
||||
'$check_fn_solutions'(first,_) :- !.
|
||||
@ -455,7 +461,8 @@ absolute_file_name(File,Opts,TrueFileName) :-
|
||||
'$add_file_to_dir'(P0,A,Atoms,NFile) :-
|
||||
atom_concat([P0,A,Atoms],NFile).
|
||||
|
||||
/** @brief path(-Directories:list) is det [DEPRECATED]
|
||||
/**
|
||||
path(-Directories:list) is det,deprecated
|
||||
|
||||
YAP specific procedure that returns a list of user-defined directories
|
||||
in the library search-path.
|
||||
@ -467,11 +474,18 @@ path(Path) :- findall(X,'$in_path'(X),Path).
|
||||
( S = "" -> X = '.' ;
|
||||
atom_codes(X,S) ).
|
||||
|
||||
/** @brief add_to_path(+Directory:atom) is det [DEPRECATED]
|
||||
/**
|
||||
add_to_path(+Directory:atom) is det,deprecated
|
||||
|
||||
YAP-specific predicate to include directory in library search path.
|
||||
*/
|
||||
add_to_path(New) :- add_to_path(New,last).
|
||||
|
||||
/**
|
||||
add_to_path(+Directory:atom, +Position:atom) is det,deprecated
|
||||
|
||||
YAP-specific predicate to include directory in front or back of library search path.
|
||||
*/
|
||||
add_to_path(New,Pos) :-
|
||||
atom(New), !,
|
||||
'$check_path'(New,Str),
|
||||
@ -482,7 +496,7 @@ add_to_path(New,Pos) :-
|
||||
'$add_to_path'(New,last) :- !, recordz('$path',New,_).
|
||||
'$add_to_path'(New,first) :- recorda('$path',New,_).
|
||||
|
||||
/** @brief remove_from_path(+Directory:atom) is det [DEPRECATED]
|
||||
/** remove_from_path(+Directory:atom) is det,deprecated
|
||||
|
||||
*/
|
||||
remove_from_path(New) :- '$check_path'(New,Path),
|
||||
@ -494,7 +508,15 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
'$check_path'([Ch],[Ch,A]) :- !, integer(Ch), '$dir_separator'(A).
|
||||
'$check_path'([N|S],[N|SN]) :- integer(N), '$check_path'(S,SN).
|
||||
|
||||
/** @brief user:library_directory(Directory:atom)
|
||||
/**
|
||||
user:library_directory(?Directory:atom) is nondet, dynamic
|
||||
|
||||
Dynamic, multi-file predicate that succeeds when _Directory_ is a
|
||||
current library directory name. Asserted in the user module.
|
||||
|
||||
Library directories are the places where files specified in the form
|
||||
`library( _File_)` are searched by the predicates consult/1,
|
||||
reconsult/1, use_module/1, ensure_loaded/1, and load_files/2.
|
||||
|
||||
*/
|
||||
|
||||
@ -502,7 +524,8 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
|
||||
:- dynamic user:library_directory/1.
|
||||
|
||||
/** @brief user:commons_directory(Directory:atom)
|
||||
/**
|
||||
user:commons_directory(?Directory:atom) is nondet, dynamic
|
||||
|
||||
*/
|
||||
|
||||
@ -510,7 +533,8 @@ remove_from_path(New) :- '$check_path'(New,Path),
|
||||
|
||||
:- dynamic user:commons_directory/1.
|
||||
|
||||
/** @brief user:prolog_file_type(Suffix:atom, Handler:atom)
|
||||
/**
|
||||
user:prolog_file_type(?Suffix:atom, ?Handler:atom) is nondet, dynamic
|
||||
|
||||
*/
|
||||
|
||||
@ -531,7 +555,25 @@ user:prolog_file_type(A, prolog) :-
|
||||
user:prolog_file_type(A, executable) :-
|
||||
current_prolog_flag(shared_object_extension, A).
|
||||
|
||||
/** @brief user:file_search_path(+Type:atom, -Directory:atom)
|
||||
/**
|
||||
user:file_search_path(+Name:atom, -Directory:atom) is nondet
|
||||
|
||||
Allows writing file names as compound terms. The _Name_ and
|
||||
_DIRECTORY_ must be atoms. The predicate may generate multiple
|
||||
solutions. The predicate is originally defined as follows:
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog
|
||||
file_search_path(library,A) :-
|
||||
library_directory(A).
|
||||
file_search_path(system,A) :-
|
||||
prolog_flag(host_type,A).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Thus, `compile(library(A))` will search for a file using
|
||||
library_directory/1 to obtain the prefix,
|
||||
whereas 'compile(system(A))` would look at the `host_type` flag.
|
||||
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
|
121
pl/arith.yap
121
pl/arith.yap
@ -298,125 +298,4 @@ expand_expr(Op, X, Y, O, Q, P) :-
|
||||
'$preprocess_args_for_non_commutative'(X, Y, Z, W, E) :-
|
||||
'$do_and'(Z = X, Y = W, E).
|
||||
|
||||
/* Arithmetics */
|
||||
|
||||
|
||||
|
||||
% M and N nonnegative integers, N is the successor of M
|
||||
succ(M,N) :-
|
||||
(
|
||||
var(M)
|
||||
->
|
||||
(
|
||||
integer(N),
|
||||
N > 0
|
||||
->
|
||||
'$plus'(N,-1,M)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
)
|
||||
;
|
||||
integer(M),
|
||||
M >= 0
|
||||
->
|
||||
(
|
||||
var(N)
|
||||
->
|
||||
'$plus'(M,1,N)
|
||||
;
|
||||
integer(N),
|
||||
N > 0
|
||||
->
|
||||
'$plus'(M,1,N)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
).
|
||||
|
||||
'$succ_error'(M,N) :-
|
||||
var(M),
|
||||
var(N), !,
|
||||
'$do_error'(instantiation_error,succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(M),
|
||||
\+ integer(M),
|
||||
'$do_error'(type_error(integer, M),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(M),
|
||||
M < 0,
|
||||
'$do_error'(domain_error(not_less_than_zero, M),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(N),
|
||||
\+ integer(N),
|
||||
'$do_error'(type_error(integer, N),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(N),
|
||||
N < 0,
|
||||
'$do_error'(domain_error(not_less_than_zero, N),succ(M,N)).
|
||||
|
||||
|
||||
|
||||
plus(X, Y, Z) :-
|
||||
(
|
||||
var(X)
|
||||
->
|
||||
(
|
||||
integer(Y), integer(Z)
|
||||
->
|
||||
'$minus'(Z,Y,X)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
integer(X)
|
||||
->
|
||||
(
|
||||
var(Y)
|
||||
->
|
||||
(
|
||||
integer(Z)
|
||||
->
|
||||
'$minus'(Z,X,Y)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
integer(Y)
|
||||
->
|
||||
(
|
||||
integer(Z)
|
||||
->
|
||||
'$minus'(Z,Y,X)
|
||||
;
|
||||
var(Z)
|
||||
->
|
||||
'$plus'(X,Y,Z)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
).
|
||||
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(X),
|
||||
\+ integer(X),
|
||||
'$do_error'(type_error(integer, X),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(Y),
|
||||
\+ integer(Y),
|
||||
'$do_error'(type_error(integer, Y),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(Z),
|
||||
\+ integer(Z),
|
||||
'$do_error'(type_error(integer, Z),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
'$do_error'(instantiation_error,plus(X,Y,Z)).
|
||||
|
||||
|
||||
|
||||
|
170
pl/arithpreds.yap
Normal file
170
pl/arithpreds.yap
Normal file
@ -0,0 +1,170 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: arithpreds.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: arithmetical predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/**
|
||||
@file arithpreds.yap
|
||||
|
||||
@addtogroup arithmetic_preds
|
||||
|
||||
|
||||
@{
|
||||
*/
|
||||
|
||||
:- system_module(arithmetic_predicates, [
|
||||
plus/3,
|
||||
succ/2], []).
|
||||
|
||||
:- use_system_module( '$_errors', ['$do_error'/2]).
|
||||
|
||||
|
||||
/** succ(? _Int1_:int, ? _Int2_:int) is det
|
||||
*
|
||||
|
||||
True if _Int2_ = _Int1_ + 1 and _Int1_ \>= 0. At least
|
||||
one of the arguments must be instantiated to a natural number. This
|
||||
predicate raises the domain-error not_less_than_zero if called with
|
||||
a negative integer. E.g. `succ(X, 0)` fails silently and `succ(X, -1)`
|
||||
raises a domain-error. The behaviour to deal with natural numbers
|
||||
only was defined by Richard O'Keefe to support the common
|
||||
count-down-to-zero in a natural way.
|
||||
|
||||
*/
|
||||
|
||||
% M and N nonnegative integers, N is the successor of M
|
||||
succ(M,N) :-
|
||||
(
|
||||
var(M)
|
||||
->
|
||||
(
|
||||
integer(N),
|
||||
N > 0
|
||||
->
|
||||
'$plus'(N,-1,M)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
)
|
||||
;
|
||||
integer(M),
|
||||
M >= 0
|
||||
->
|
||||
(
|
||||
var(N)
|
||||
->
|
||||
'$plus'(M,1,N)
|
||||
;
|
||||
integer(N),
|
||||
N > 0
|
||||
->
|
||||
'$plus'(M,1,N)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
)
|
||||
;
|
||||
'$succ_error'(M,N)
|
||||
).
|
||||
|
||||
'$succ_error'(M,N) :-
|
||||
var(M),
|
||||
var(N), !,
|
||||
'$do_error'(instantiation_error,succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(M),
|
||||
\+ integer(M),
|
||||
'$do_error'(type_error(integer, M),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(M),
|
||||
M < 0,
|
||||
'$do_error'(domain_error(not_less_than_zero, M),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(N),
|
||||
\+ integer(N),
|
||||
'$do_error'(type_error(integer, N),succ(M,N)).
|
||||
'$succ_error'(M,N) :-
|
||||
nonvar(N),
|
||||
N < 0,
|
||||
'$do_error'(domain_error(not_less_than_zero, N),succ(M,N)).
|
||||
|
||||
/** 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.
|
||||
|
||||
@}
|
||||
|
||||
*/
|
||||
|
||||
plus(X, Y, Z) :-
|
||||
(
|
||||
var(X)
|
||||
->
|
||||
(
|
||||
integer(Y), integer(Z)
|
||||
->
|
||||
'$minus'(Z,Y,X)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
integer(X)
|
||||
->
|
||||
(
|
||||
var(Y)
|
||||
->
|
||||
(
|
||||
integer(Z)
|
||||
->
|
||||
'$minus'(Z,X,Y)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
integer(Y)
|
||||
->
|
||||
(
|
||||
integer(Z)
|
||||
->
|
||||
'$minus'(Z,Y,X)
|
||||
;
|
||||
var(Z)
|
||||
->
|
||||
'$plus'(X,Y,Z)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
)
|
||||
;
|
||||
'$plus_error'(X,Y,Z)
|
||||
).
|
||||
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(X),
|
||||
\+ integer(X),
|
||||
'$do_error'(type_error(integer, X),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(Y),
|
||||
\+ integer(Y),
|
||||
'$do_error'(type_error(integer, Y),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
nonvar(Z),
|
||||
\+ integer(Z),
|
||||
'$do_error'(type_error(integer, Z),plus(X,Y,Z)).
|
||||
'$plus_error'(X,Y,Z) :-
|
||||
'$do_error'(instantiation_error,plus(X,Y,Z)).
|
||||
|
||||
|
@ -114,6 +114,7 @@ otherwise.
|
||||
'ground.yap',
|
||||
'listing.yap',
|
||||
'preds.yap',
|
||||
'arithpreds,yap',
|
||||
% modules must be after preds, otherwise we will have trouble
|
||||
% with meta-predicate expansion being invoked
|
||||
'modules.yap',
|
||||
|
Reference in New Issue
Block a user