Merge branch 'master' of git.dcc.fc.up.pt:yap-6.3
This commit is contained in:
commit
6591b5429c
93
C/arith0.c
93
C/arith0.c
@ -18,8 +18,72 @@
|
|||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#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:
|
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");
|
Yap_Error(TYPE_ERROR_EVALUABLE, TermNil, "evaluating infinity");
|
||||||
P = (yamop *)FAILCODE;
|
P = (yamop *)FAILCODE;
|
||||||
RERROR();
|
RERROR();
|
||||||
@ -112,40 +176,62 @@ eval0(Int fi) {
|
|||||||
RFLOAT((Float)Yap_cputime()/1000.0);
|
RFLOAT((Float)Yap_cputime()/1000.0);
|
||||||
}
|
}
|
||||||
case op_heapused:
|
case op_heapused:
|
||||||
|
/// - heapused
|
||||||
|
/// Heap (data-base) space used, in bytes.
|
||||||
|
///
|
||||||
RINT(HeapUsed);
|
RINT(HeapUsed);
|
||||||
case op_localsp:
|
case op_localsp:
|
||||||
|
/// - local
|
||||||
|
/// Local stack in use, in bytes
|
||||||
|
///
|
||||||
#if YAPOR_SBA
|
#if YAPOR_SBA
|
||||||
RINT((Int)ASP);
|
RINT((Int)ASP);
|
||||||
#else
|
#else
|
||||||
RINT(LCL0 - ASP);
|
RINT(LCL0 - ASP);
|
||||||
#endif
|
#endif
|
||||||
case op_b:
|
case op_b:
|
||||||
|
/// - $b
|
||||||
|
/// current choicepoint
|
||||||
|
///
|
||||||
#if YAPOR_SBA
|
#if YAPOR_SBA
|
||||||
RINT((Int)B);
|
RINT((Int)B);
|
||||||
#else
|
#else
|
||||||
RINT(LCL0 - (CELL *)B);
|
RINT(LCL0 - (CELL *)B);
|
||||||
#endif
|
#endif
|
||||||
case op_env:
|
case op_env:
|
||||||
|
/// - $env
|
||||||
|
/// Environment
|
||||||
|
///
|
||||||
#if YAPOR_SBA
|
#if YAPOR_SBA
|
||||||
RINT((Int)YENV);
|
RINT((Int)YENV);
|
||||||
#else
|
#else
|
||||||
RINT(LCL0 - YENV);
|
RINT(LCL0 - YENV);
|
||||||
#endif
|
#endif
|
||||||
case op_tr:
|
case op_tr:
|
||||||
|
/// - $tr
|
||||||
|
/// Trail in use
|
||||||
|
///
|
||||||
#if YAPOR_SBA
|
#if YAPOR_SBA
|
||||||
RINT(TR);
|
RINT(TR);
|
||||||
#else
|
#else
|
||||||
RINT(((CELL *)TR)-LCL0);
|
RINT(((CELL *)TR)-LCL0);
|
||||||
#endif
|
#endif
|
||||||
case op_stackfree:
|
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));
|
RINT(Unsigned(ASP) - Unsigned(HR));
|
||||||
case op_globalsp:
|
case op_globalsp:
|
||||||
|
/// - global
|
||||||
|
/// Global stack in use, in bytes.
|
||||||
|
///
|
||||||
#if YAPOR_SBA
|
#if YAPOR_SBA
|
||||||
RINT((Int)HR);
|
RINT((Int)HR);
|
||||||
#else
|
#else
|
||||||
RINT(HR - H0);
|
RINT(HR - H0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
/// end of switch
|
||||||
RERROR();
|
RERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,3 +296,4 @@ Yap_ReInitConstExps(void)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
211
C/arith1.c
211
C/arith1.c
@ -18,10 +18,212 @@
|
|||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#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 "Yap.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
@ -694,6 +896,7 @@ eval1(Int fi, Term t USES_REGS) {
|
|||||||
RERROR();
|
RERROR();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// end of switch
|
||||||
RERROR();
|
RERROR();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
109
C/arith2.c
109
C/arith2.c
@ -18,10 +18,111 @@
|
|||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#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 "Yap.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
|
@ -1998,7 +1998,6 @@ static void expand_consult( void )
|
|||||||
LOCAL_ConsultLow = new_cl;
|
LOCAL_ConsultLow = new_cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* p was already locked */
|
|
||||||
static int
|
static int
|
||||||
not_was_reconsulted(PredEntry *p, Term t, int mode)
|
not_was_reconsulted(PredEntry *p, Term t, int mode)
|
||||||
{
|
{
|
||||||
@ -6458,7 +6457,6 @@ p_nth_instance( USES_REGS1 )
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitCdMgr(void)
|
Yap_InitCdMgr(void)
|
||||||
{
|
{
|
||||||
|
75
C/cmppreds.c
75
C/cmppreds.c
@ -14,6 +14,10 @@
|
|||||||
* comments: comparing two prolog terms *
|
* comments: comparing two prolog terms *
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
/// @file cmppreds.c
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef SCCS
|
#ifdef SCCS
|
||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#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
|
Int
|
||||||
Yap_acmp(Term t1, Term t2 USES_REGS)
|
Yap_acmp(Term t1, Term t2 USES_REGS)
|
||||||
{
|
{
|
||||||
@ -667,6 +682,15 @@ p_acomp( USES_REGS1 )
|
|||||||
return out;
|
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
|
static Int
|
||||||
a_eq(Term t1, Term t2)
|
a_eq(Term t1, Term t2)
|
||||||
{
|
{
|
||||||
@ -701,6 +725,15 @@ a_eq(Term t1, Term t2)
|
|||||||
return out == 0;
|
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
|
static Int
|
||||||
a_dif(Term t1, Term t2)
|
a_dif(Term t1, Term t2)
|
||||||
{
|
{
|
||||||
@ -710,6 +743,16 @@ a_dif(Term t1, Term t2)
|
|||||||
return out != 0;
|
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
|
static Int
|
||||||
a_gt(Term t1, Term t2)
|
a_gt(Term t1, Term t2)
|
||||||
{ /* A > B */
|
{ /* A > B */
|
||||||
@ -719,6 +762,16 @@ a_gt(Term t1, Term t2)
|
|||||||
return out > 0;
|
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
|
static Int
|
||||||
a_ge(Term t1, Term t2)
|
a_ge(Term t1, Term t2)
|
||||||
{ /* A >= B */
|
{ /* A >= B */
|
||||||
@ -728,6 +781,16 @@ a_ge(Term t1, Term t2)
|
|||||||
return out >= 0;
|
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
|
static Int
|
||||||
a_lt(Term t1, Term t2)
|
a_lt(Term t1, Term t2)
|
||||||
{ /* A < B */
|
{ /* A < B */
|
||||||
@ -737,6 +800,17 @@ a_lt(Term t1, Term t2)
|
|||||||
return out < 0;
|
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
|
static Int
|
||||||
a_le(Term t1, Term t2)
|
a_le(Term t1, Term t2)
|
||||||
{ /* A <= B */
|
{ /* A <= B */
|
||||||
@ -746,6 +820,7 @@ a_le(Term t1, Term t2)
|
|||||||
return out <= 0;
|
return out <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @}
|
||||||
|
|
||||||
static Int
|
static Int
|
||||||
a_noteq(Term t1, Term t2)
|
a_noteq(Term t1, Term t2)
|
||||||
|
83
C/eval.c
83
C/eval.c
@ -18,10 +18,16 @@
|
|||||||
static char SccsId[] = "%W% %G%";
|
static char SccsId[] = "%W% %G%";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* This file implements arithmetic operations
|
@file eval.c
|
||||||
*
|
|
||||||
*/
|
@defgroup arithmetic_preds Arithmetic Predicates
|
||||||
|
@ingroup arithmetic
|
||||||
|
|
||||||
|
@{
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
@ -184,6 +190,23 @@ BEAM_is(void)
|
|||||||
|
|
||||||
#endif
|
#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
|
static Int
|
||||||
p_is( USES_REGS1 )
|
p_is( USES_REGS1 )
|
||||||
{ /* X is Y */
|
{ /* X is Y */
|
||||||
@ -204,6 +227,16 @@ p_is( USES_REGS1 )
|
|||||||
return Yap_unify_constant(ARG1,out);
|
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
|
static Int
|
||||||
p_isnan( USES_REGS1 )
|
p_isnan( USES_REGS1 )
|
||||||
{ /* X is Y */
|
{ /* X is Y */
|
||||||
@ -232,6 +265,17 @@ p_isnan( USES_REGS1 )
|
|||||||
return isnan(FloatOfTerm(out));
|
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
|
static Int
|
||||||
p_isinf( USES_REGS1 )
|
p_isinf( USES_REGS1 )
|
||||||
{ /* X is Y */
|
{ /* X is Y */
|
||||||
@ -260,6 +304,18 @@ p_isinf( USES_REGS1 )
|
|||||||
return isinf(FloatOfTerm(out));
|
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
|
static Int
|
||||||
p_logsum( USES_REGS1 )
|
p_logsum( USES_REGS1 )
|
||||||
{ /* X is Y */
|
{ /* 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
|
static Int
|
||||||
init_between( USES_REGS1 )
|
init_between( USES_REGS1 )
|
||||||
{
|
{
|
||||||
|
72
C/iopreds.c
72
C/iopreds.c
@ -553,6 +553,7 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
|||||||
} else {
|
} else {
|
||||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||||
rd->varnames = 0;
|
rd->varnames = 0;
|
||||||
|
rd->singles = 0;
|
||||||
return Yap_unify_constant( Yap_GetFromSlot( t0 PASS_REGS), MkAtomTerm (AtomEof));
|
return Yap_unify_constant( Yap_GetFromSlot( t0 PASS_REGS), MkAtomTerm (AtomEof));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -636,7 +637,6 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (rd->variables) {
|
if (rd->variables) {
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
CELL *old_H = HR;
|
CELL *old_H = HR;
|
||||||
@ -680,9 +680,16 @@ Yap_read_term(term_t t0, IOSTREAM *inp_stream, struct read_data_t *rd)
|
|||||||
TR = old_TR;
|
TR = old_TR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Yap_unify(v, Yap_GetFromSlot( rd->singles PASS_REGS)))
|
if (rd->singles == 1) {
|
||||||
|
if (IsPairTerm(v))
|
||||||
|
rd->singles = Yap_InitSlot( v PASS_REGS);
|
||||||
|
else
|
||||||
|
rd->singles = FALSE;
|
||||||
|
} else if (rd->singles) {
|
||||||
|
if (!Yap_unify( rd->singles, Yap_GetFromSlot( v PASS_REGS )))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
Yap_clean_tokenizer(tokstart, LOCAL_VarTable, LOCAL_AnonVarTable, LOCAL_Comments);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -871,6 +878,65 @@ p_float_format( USES_REGS1 )
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Int
|
||||||
|
p_style_checker( USES_REGS1 )
|
||||||
|
{
|
||||||
|
Term t = Deref( ARG1 );
|
||||||
|
LD_FROM_REGS
|
||||||
|
|
||||||
|
if (IsVarTerm(t)) {
|
||||||
|
Term t = TermNil;
|
||||||
|
if ( debugstatus.styleCheck & LONGATOM_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomAtom), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & SINGLETON_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomSingleton), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & MULTITON_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomVarBranches), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & DISCONTIGUOUS_STYLE) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomDiscontiguous), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & NOEFFECT_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomNoEffect), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & CHARSET_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomCharset), t );
|
||||||
|
}
|
||||||
|
if ( debugstatus.styleCheck & MULTIPLE_CHECK) {
|
||||||
|
t = MkPairTerm( MkAtomTerm(AtomMultiple), t );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (IsPairTerm(t)) {
|
||||||
|
Term h = HeadOfTerm( t );
|
||||||
|
t = TailOfTerm( t );
|
||||||
|
|
||||||
|
if (IsAtomTerm(h)) {
|
||||||
|
Atom at = AtomOfTerm( h );
|
||||||
|
if (at == AtomAtom) debugstatus.styleCheck |= LONGATOM_CHECK;
|
||||||
|
else if (at == AtomSingleton) debugstatus.styleCheck |= SINGLETON_CHECK;
|
||||||
|
else if (at == AtomVarBranches) debugstatus.styleCheck |= MULTITON_CHECK;
|
||||||
|
else if (at == AtomDiscontiguous) debugstatus.styleCheck |= DISCONTIGUOUS_STYLE;
|
||||||
|
else if (at == AtomNoEffect) debugstatus.styleCheck |= NOEFFECT_CHECK;
|
||||||
|
else if (at == AtomCharset) debugstatus.styleCheck |= CHARSET_CHECK;
|
||||||
|
else if (at == AtomMultiple) debugstatus.styleCheck |= MULTIPLE_CHECK;
|
||||||
|
} else {
|
||||||
|
Atom at = AtomOfTerm( ArgOfTerm( 1, h ) );
|
||||||
|
if (at == AtomAtom) debugstatus.styleCheck |= LONGATOM_CHECK;
|
||||||
|
else if (at == AtomSingleton) debugstatus.styleCheck &= ~SINGLETON_CHECK;
|
||||||
|
else if (at == AtomVarBranches) debugstatus.styleCheck &= ~MULTITON_CHECK;
|
||||||
|
else if (at == AtomDiscontiguous) debugstatus.styleCheck &= ~DISCONTIGUOUS_STYLE;
|
||||||
|
else if (at == AtomNoEffect) debugstatus.styleCheck &= ~NOEFFECT_CHECK;
|
||||||
|
else if (at == AtomMultiple) debugstatus.styleCheck &= ~MULTIPLE_CHECK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Yap_InitBackIO (void)
|
Yap_InitBackIO (void)
|
||||||
{
|
{
|
||||||
@ -915,5 +981,5 @@ Yap_InitIOPreds(void)
|
|||||||
// Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
// Yap_InitCPred ("stream_select", 3, p_stream_select, SafePredFlag|SyncPredFlag);
|
||||||
#endif
|
#endif
|
||||||
Yap_InitCPred ("$float_format", 1, p_float_format, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred ("$float_format", 1, p_float_format, SafePredFlag|SyncPredFlag);
|
||||||
|
Yap_InitCPred ("$style_checker", 1, p_style_checker, SyncPredFlag);
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,9 @@ LookupModule(Term a )
|
|||||||
ModEntry *me;
|
ModEntry *me;
|
||||||
|
|
||||||
/* prolog module */
|
/* prolog module */
|
||||||
if (a == 0)
|
if (a == 0) {
|
||||||
return GetModuleEntry(AtomProlog);
|
return GetModuleEntry(AtomProlog);
|
||||||
|
}
|
||||||
at = AtomOfTerm(a);
|
at = AtomOfTerm(a);
|
||||||
me = GetModuleEntry(at);
|
me = GetModuleEntry(at);
|
||||||
return me;
|
return me;
|
||||||
|
@ -146,7 +146,7 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
|||||||
// if (!worker_id) return;
|
// if (!worker_id) return;
|
||||||
LOCK(Yap_heap_regs->low_level_trace_lock);
|
LOCK(Yap_heap_regs->low_level_trace_lock);
|
||||||
sc = Yap_heap_regs;
|
sc = Yap_heap_regs;
|
||||||
//if (vsc_count == 54) jmp_deb(1);
|
if (vsc_count == 161862) jmp_deb(1);
|
||||||
// Sfprintf(stderr,"B=%p ", B);
|
// Sfprintf(stderr,"B=%p ", B);
|
||||||
#ifdef THREADS
|
#ifdef THREADS
|
||||||
LOCAL_ThreadHandle.thread_inst_count++;
|
LOCAL_ThreadHandle.thread_inst_count++;
|
||||||
|
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>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* C library used to implement floating point functions */
|
/* C library used to implement floating point functions */
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
AtomCharsio = Yap_LookupAtom("charsio");
|
AtomCharsio = Yap_LookupAtom("charsio");
|
||||||
AtomCharacter = Yap_LookupAtom("character");
|
AtomCharacter = Yap_LookupAtom("character");
|
||||||
AtomCharacterCode = Yap_LookupAtom("character_code");
|
AtomCharacterCode = Yap_LookupAtom("character_code");
|
||||||
|
AtomCharset = Yap_LookupAtom("charset");
|
||||||
AtomCleanCall = Yap_FullLookupAtom("$clean_call");
|
AtomCleanCall = Yap_FullLookupAtom("$clean_call");
|
||||||
AtomColomn = Yap_LookupAtom(":");
|
AtomColomn = Yap_LookupAtom(":");
|
||||||
AtomCodeSpace = Yap_LookupAtom("code_space");
|
AtomCodeSpace = Yap_LookupAtom("code_space");
|
||||||
@ -81,6 +82,7 @@
|
|||||||
AtomDefault = Yap_LookupAtom("default");
|
AtomDefault = Yap_LookupAtom("default");
|
||||||
AtomDevNull = Yap_LookupAtom("/dev/null");
|
AtomDevNull = Yap_LookupAtom("/dev/null");
|
||||||
AtomDiff = Yap_LookupAtom("\\=");
|
AtomDiff = Yap_LookupAtom("\\=");
|
||||||
|
AtomDiscontiguous = Yap_LookupAtom("discontiguous");
|
||||||
AtomDollar = Yap_FullLookupAtom("$");
|
AtomDollar = Yap_FullLookupAtom("$");
|
||||||
AtomDoLogUpdClause = Yap_FullLookupAtom("$do_log_upd_clause");
|
AtomDoLogUpdClause = Yap_FullLookupAtom("$do_log_upd_clause");
|
||||||
AtomDoLogUpdClause0 = Yap_FullLookupAtom("$do_log_upd_clause0");
|
AtomDoLogUpdClause0 = Yap_FullLookupAtom("$do_log_upd_clause0");
|
||||||
@ -183,6 +185,7 @@
|
|||||||
AtomModify = Yap_LookupAtom("modify");
|
AtomModify = Yap_LookupAtom("modify");
|
||||||
AtomMost = Yap_LookupAtom("most");
|
AtomMost = Yap_LookupAtom("most");
|
||||||
AtomMultiFile = Yap_FullLookupAtom("$mf");
|
AtomMultiFile = Yap_FullLookupAtom("$mf");
|
||||||
|
AtomMultiple = Yap_FullLookupAtom("multiple");
|
||||||
AtomMutable = Yap_LookupAtom("mutable");
|
AtomMutable = Yap_LookupAtom("mutable");
|
||||||
AtomMutableVariable = Yap_FullLookupAtom("$mutable_variable");
|
AtomMutableVariable = Yap_FullLookupAtom("$mutable_variable");
|
||||||
AtomMyddasDB = Yap_FullLookupAtom("$myddas_db");
|
AtomMyddasDB = Yap_FullLookupAtom("$myddas_db");
|
||||||
@ -195,6 +198,7 @@
|
|||||||
AtomNb = Yap_LookupAtom("nb");
|
AtomNb = Yap_LookupAtom("nb");
|
||||||
AtomNbTerm = Yap_LookupAtom("nb_term");
|
AtomNbTerm = Yap_LookupAtom("nb_term");
|
||||||
AtomNew = Yap_LookupAtom("new");
|
AtomNew = Yap_LookupAtom("new");
|
||||||
|
AtomNoEffect = Yap_LookupAtom("no_effect");
|
||||||
AtomNoMemory = Yap_LookupAtom("no_memory");
|
AtomNoMemory = Yap_LookupAtom("no_memory");
|
||||||
AtomNone = Yap_LookupAtom("none");
|
AtomNone = Yap_LookupAtom("none");
|
||||||
AtomNonEmptyList = Yap_LookupAtom("non_empty_list");
|
AtomNonEmptyList = Yap_LookupAtom("non_empty_list");
|
||||||
@ -282,6 +286,7 @@
|
|||||||
AtomSigUsr2 = Yap_LookupAtom("sig_usr2");
|
AtomSigUsr2 = Yap_LookupAtom("sig_usr2");
|
||||||
AtomSigVTAlarm = Yap_LookupAtom("sig_vtalarm");
|
AtomSigVTAlarm = Yap_LookupAtom("sig_vtalarm");
|
||||||
AtomSigWakeUp = Yap_LookupAtom("sig_wake_up");
|
AtomSigWakeUp = Yap_LookupAtom("sig_wake_up");
|
||||||
|
AtomSingleton = Yap_LookupAtom("singleton");
|
||||||
AtomSlash = Yap_LookupAtom("/");
|
AtomSlash = Yap_LookupAtom("/");
|
||||||
AtomSocket = Yap_LookupAtom("socket");
|
AtomSocket = Yap_LookupAtom("socket");
|
||||||
AtomSourceSink = Yap_LookupAtom("source_sink");
|
AtomSourceSink = Yap_LookupAtom("source_sink");
|
||||||
@ -335,6 +340,7 @@
|
|||||||
AtomUserOut = Yap_LookupAtom("user_output");
|
AtomUserOut = Yap_LookupAtom("user_output");
|
||||||
AtomVBar = Yap_LookupAtom("|");
|
AtomVBar = Yap_LookupAtom("|");
|
||||||
AtomVar = Yap_FullLookupAtom("$VAR");
|
AtomVar = Yap_FullLookupAtom("$VAR");
|
||||||
|
AtomVarBranches = Yap_LookupAtom("var_branches");
|
||||||
AtomHiddenVar = Yap_FullLookupAtom("$V");
|
AtomHiddenVar = Yap_FullLookupAtom("$V");
|
||||||
AtomVariable = Yap_LookupAtom("variable");
|
AtomVariable = Yap_LookupAtom("variable");
|
||||||
AtomVersionNumber = Yap_FullLookupAtom("$version_name");
|
AtomVersionNumber = Yap_FullLookupAtom("$version_name");
|
||||||
|
@ -127,8 +127,6 @@ typedef int Char; /* char that can pass EOF */
|
|||||||
#define source_char_no (LD->read_source.position.charno)
|
#define source_char_no (LD->read_source.position.charno)
|
||||||
#define source_byte_no (LD->read_source.position.byteno)
|
#define source_byte_no (LD->read_source.position.byteno)
|
||||||
|
|
||||||
#define debugstatus (LD->_debugstatus)
|
|
||||||
|
|
||||||
#if SIZE_DOUBLE==SIZEOF_INT_P
|
#if SIZE_DOUBLE==SIZEOF_INT_P
|
||||||
#define WORDS_PER_DOUBLE 1
|
#define WORDS_PER_DOUBLE 1
|
||||||
#else
|
#else
|
||||||
@ -306,10 +304,6 @@ typedef struct
|
|||||||
word culprit; /* for CVT_nocode/CVT_nochar */
|
word culprit; /* for CVT_nocode/CVT_nochar */
|
||||||
} CVT_result;
|
} CVT_result;
|
||||||
|
|
||||||
#define MAXNEWLINES 5 /* maximum # of newlines in atom */
|
|
||||||
|
|
||||||
#define LONGATOM_CHECK 0x01 /* read/1: error on intptr_t atoms */
|
|
||||||
|
|
||||||
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
Operator types. NOTE: if you change OP_*, check operatorTypeToAtom()!
|
Operator types. NOTE: if you change OP_*, check operatorTypeToAtom()!
|
||||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||||
@ -454,6 +448,7 @@ extern int fileerrors;
|
|||||||
|
|
||||||
extern int ttymode;
|
extern int ttymode;
|
||||||
|
|
||||||
|
|
||||||
#define CHARESCAPE_FEATURE 0x00001 /* handle \ in atoms */
|
#define CHARESCAPE_FEATURE 0x00001 /* handle \ in atoms */
|
||||||
#define GC_FEATURE 0x00002 /* do GC */
|
#define GC_FEATURE 0x00002 /* do GC */
|
||||||
#define TRACE_GC_FEATURE 0x00004 /* verbose gc */
|
#define TRACE_GC_FEATURE 0x00004 /* verbose gc */
|
||||||
|
@ -258,6 +258,22 @@ typedef struct initialise_handle * InitialiseHandle;
|
|||||||
extern unsigned int
|
extern unsigned int
|
||||||
getUnknownModule(module_t m);
|
getUnknownModule(module_t m);
|
||||||
|
|
||||||
|
/* keep in sync with style_name/1 in boot/prims.pl */
|
||||||
|
|
||||||
|
#define LONGATOM_CHECK 0x0001 /* read/1: error on intptr_t atoms */
|
||||||
|
#define SINGLETON_CHECK 0x0002 /* read/1: check singleton vars */
|
||||||
|
#define MULTITON_CHECK 0x0004 /* read/1: check multiton vars */
|
||||||
|
#define DISCONTIGUOUS_STYLE 0x0008 /* warn on discontiguous predicates */
|
||||||
|
#define DYNAMIC_STYLE 0x0010 /* warn on assert/retract active */
|
||||||
|
#define CHARSET_CHECK 0x0020 /* warn on unquoted characters */
|
||||||
|
#define SEMSINGLETON_CHECK 0x0040 /* Semantic singleton checking */
|
||||||
|
#define NOEFFECT_CHECK 0x0080 /* Check for meaningless statements */
|
||||||
|
#define VARBRANCH_CHECK 0x0100 /* warn on unbalanced variables */
|
||||||
|
#define MULTIPLE_CHECK 0x0100 /* warn on multiple file definitions for a predicate */
|
||||||
|
#define MAXNEWLINES 5 /* maximum # of newlines in atom */
|
||||||
|
|
||||||
|
#define debugstatus (LD->_debugstatus)
|
||||||
|
|
||||||
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
|
#define truePrologFlag(flag) true(&LD->prolog_flag.mask, flag)
|
||||||
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
|
#define setPrologFlagMask(flag) set(&LD->prolog_flag.mask, flag)
|
||||||
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
|
#define clearPrologFlagMask(flag) clear(&LD->prolog_flag.mask, flag)
|
||||||
|
@ -50,6 +50,7 @@
|
|||||||
AtomCharsio = AtomAdjust(AtomCharsio);
|
AtomCharsio = AtomAdjust(AtomCharsio);
|
||||||
AtomCharacter = AtomAdjust(AtomCharacter);
|
AtomCharacter = AtomAdjust(AtomCharacter);
|
||||||
AtomCharacterCode = AtomAdjust(AtomCharacterCode);
|
AtomCharacterCode = AtomAdjust(AtomCharacterCode);
|
||||||
|
AtomCharset = AtomAdjust(AtomCharset);
|
||||||
AtomCleanCall = AtomAdjust(AtomCleanCall);
|
AtomCleanCall = AtomAdjust(AtomCleanCall);
|
||||||
AtomColomn = AtomAdjust(AtomColomn);
|
AtomColomn = AtomAdjust(AtomColomn);
|
||||||
AtomCodeSpace = AtomAdjust(AtomCodeSpace);
|
AtomCodeSpace = AtomAdjust(AtomCodeSpace);
|
||||||
@ -81,6 +82,7 @@
|
|||||||
AtomDefault = AtomAdjust(AtomDefault);
|
AtomDefault = AtomAdjust(AtomDefault);
|
||||||
AtomDevNull = AtomAdjust(AtomDevNull);
|
AtomDevNull = AtomAdjust(AtomDevNull);
|
||||||
AtomDiff = AtomAdjust(AtomDiff);
|
AtomDiff = AtomAdjust(AtomDiff);
|
||||||
|
AtomDiscontiguous = AtomAdjust(AtomDiscontiguous);
|
||||||
AtomDollar = AtomAdjust(AtomDollar);
|
AtomDollar = AtomAdjust(AtomDollar);
|
||||||
AtomDoLogUpdClause = AtomAdjust(AtomDoLogUpdClause);
|
AtomDoLogUpdClause = AtomAdjust(AtomDoLogUpdClause);
|
||||||
AtomDoLogUpdClause0 = AtomAdjust(AtomDoLogUpdClause0);
|
AtomDoLogUpdClause0 = AtomAdjust(AtomDoLogUpdClause0);
|
||||||
@ -183,6 +185,7 @@
|
|||||||
AtomModify = AtomAdjust(AtomModify);
|
AtomModify = AtomAdjust(AtomModify);
|
||||||
AtomMost = AtomAdjust(AtomMost);
|
AtomMost = AtomAdjust(AtomMost);
|
||||||
AtomMultiFile = AtomAdjust(AtomMultiFile);
|
AtomMultiFile = AtomAdjust(AtomMultiFile);
|
||||||
|
AtomMultiple = AtomAdjust(AtomMultiple);
|
||||||
AtomMutable = AtomAdjust(AtomMutable);
|
AtomMutable = AtomAdjust(AtomMutable);
|
||||||
AtomMutableVariable = AtomAdjust(AtomMutableVariable);
|
AtomMutableVariable = AtomAdjust(AtomMutableVariable);
|
||||||
AtomMyddasDB = AtomAdjust(AtomMyddasDB);
|
AtomMyddasDB = AtomAdjust(AtomMyddasDB);
|
||||||
@ -195,6 +198,7 @@
|
|||||||
AtomNb = AtomAdjust(AtomNb);
|
AtomNb = AtomAdjust(AtomNb);
|
||||||
AtomNbTerm = AtomAdjust(AtomNbTerm);
|
AtomNbTerm = AtomAdjust(AtomNbTerm);
|
||||||
AtomNew = AtomAdjust(AtomNew);
|
AtomNew = AtomAdjust(AtomNew);
|
||||||
|
AtomNoEffect = AtomAdjust(AtomNoEffect);
|
||||||
AtomNoMemory = AtomAdjust(AtomNoMemory);
|
AtomNoMemory = AtomAdjust(AtomNoMemory);
|
||||||
AtomNone = AtomAdjust(AtomNone);
|
AtomNone = AtomAdjust(AtomNone);
|
||||||
AtomNonEmptyList = AtomAdjust(AtomNonEmptyList);
|
AtomNonEmptyList = AtomAdjust(AtomNonEmptyList);
|
||||||
@ -282,6 +286,7 @@
|
|||||||
AtomSigUsr2 = AtomAdjust(AtomSigUsr2);
|
AtomSigUsr2 = AtomAdjust(AtomSigUsr2);
|
||||||
AtomSigVTAlarm = AtomAdjust(AtomSigVTAlarm);
|
AtomSigVTAlarm = AtomAdjust(AtomSigVTAlarm);
|
||||||
AtomSigWakeUp = AtomAdjust(AtomSigWakeUp);
|
AtomSigWakeUp = AtomAdjust(AtomSigWakeUp);
|
||||||
|
AtomSingleton = AtomAdjust(AtomSingleton);
|
||||||
AtomSlash = AtomAdjust(AtomSlash);
|
AtomSlash = AtomAdjust(AtomSlash);
|
||||||
AtomSocket = AtomAdjust(AtomSocket);
|
AtomSocket = AtomAdjust(AtomSocket);
|
||||||
AtomSourceSink = AtomAdjust(AtomSourceSink);
|
AtomSourceSink = AtomAdjust(AtomSourceSink);
|
||||||
@ -335,6 +340,7 @@
|
|||||||
AtomUserOut = AtomAdjust(AtomUserOut);
|
AtomUserOut = AtomAdjust(AtomUserOut);
|
||||||
AtomVBar = AtomAdjust(AtomVBar);
|
AtomVBar = AtomAdjust(AtomVBar);
|
||||||
AtomVar = AtomAdjust(AtomVar);
|
AtomVar = AtomAdjust(AtomVar);
|
||||||
|
AtomVarBranches = AtomAdjust(AtomVarBranches);
|
||||||
AtomHiddenVar = AtomAdjust(AtomHiddenVar);
|
AtomHiddenVar = AtomAdjust(AtomHiddenVar);
|
||||||
AtomVariable = AtomAdjust(AtomVariable);
|
AtomVariable = AtomAdjust(AtomVariable);
|
||||||
AtomVersionNumber = AtomAdjust(AtomVersionNumber);
|
AtomVersionNumber = AtomAdjust(AtomVersionNumber);
|
||||||
|
12
H/tatoms.h
12
H/tatoms.h
@ -98,6 +98,8 @@
|
|||||||
#define AtomCharacter Yap_heap_regs->AtomCharacter_
|
#define AtomCharacter Yap_heap_regs->AtomCharacter_
|
||||||
Atom AtomCharacterCode_;
|
Atom AtomCharacterCode_;
|
||||||
#define AtomCharacterCode Yap_heap_regs->AtomCharacterCode_
|
#define AtomCharacterCode Yap_heap_regs->AtomCharacterCode_
|
||||||
|
Atom AtomCharset_;
|
||||||
|
#define AtomCharset Yap_heap_regs->AtomCharset_
|
||||||
Atom AtomCleanCall_;
|
Atom AtomCleanCall_;
|
||||||
#define AtomCleanCall Yap_heap_regs->AtomCleanCall_
|
#define AtomCleanCall Yap_heap_regs->AtomCleanCall_
|
||||||
Atom AtomColomn_;
|
Atom AtomColomn_;
|
||||||
@ -160,6 +162,8 @@
|
|||||||
#define AtomDevNull Yap_heap_regs->AtomDevNull_
|
#define AtomDevNull Yap_heap_regs->AtomDevNull_
|
||||||
Atom AtomDiff_;
|
Atom AtomDiff_;
|
||||||
#define AtomDiff Yap_heap_regs->AtomDiff_
|
#define AtomDiff Yap_heap_regs->AtomDiff_
|
||||||
|
Atom AtomDiscontiguous_;
|
||||||
|
#define AtomDiscontiguous Yap_heap_regs->AtomDiscontiguous_
|
||||||
Atom AtomDollar_;
|
Atom AtomDollar_;
|
||||||
#define AtomDollar Yap_heap_regs->AtomDollar_
|
#define AtomDollar Yap_heap_regs->AtomDollar_
|
||||||
Atom AtomDoLogUpdClause_;
|
Atom AtomDoLogUpdClause_;
|
||||||
@ -364,6 +368,8 @@
|
|||||||
#define AtomMost Yap_heap_regs->AtomMost_
|
#define AtomMost Yap_heap_regs->AtomMost_
|
||||||
Atom AtomMultiFile_;
|
Atom AtomMultiFile_;
|
||||||
#define AtomMultiFile Yap_heap_regs->AtomMultiFile_
|
#define AtomMultiFile Yap_heap_regs->AtomMultiFile_
|
||||||
|
Atom AtomMultiple_;
|
||||||
|
#define AtomMultiple Yap_heap_regs->AtomMultiple_
|
||||||
Atom AtomMutable_;
|
Atom AtomMutable_;
|
||||||
#define AtomMutable Yap_heap_regs->AtomMutable_
|
#define AtomMutable Yap_heap_regs->AtomMutable_
|
||||||
Atom AtomMutableVariable_;
|
Atom AtomMutableVariable_;
|
||||||
@ -388,6 +394,8 @@
|
|||||||
#define AtomNbTerm Yap_heap_regs->AtomNbTerm_
|
#define AtomNbTerm Yap_heap_regs->AtomNbTerm_
|
||||||
Atom AtomNew_;
|
Atom AtomNew_;
|
||||||
#define AtomNew Yap_heap_regs->AtomNew_
|
#define AtomNew Yap_heap_regs->AtomNew_
|
||||||
|
Atom AtomNoEffect_;
|
||||||
|
#define AtomNoEffect Yap_heap_regs->AtomNoEffect_
|
||||||
Atom AtomNoMemory_;
|
Atom AtomNoMemory_;
|
||||||
#define AtomNoMemory Yap_heap_regs->AtomNoMemory_
|
#define AtomNoMemory Yap_heap_regs->AtomNoMemory_
|
||||||
Atom AtomNone_;
|
Atom AtomNone_;
|
||||||
@ -562,6 +570,8 @@
|
|||||||
#define AtomSigVTAlarm Yap_heap_regs->AtomSigVTAlarm_
|
#define AtomSigVTAlarm Yap_heap_regs->AtomSigVTAlarm_
|
||||||
Atom AtomSigWakeUp_;
|
Atom AtomSigWakeUp_;
|
||||||
#define AtomSigWakeUp Yap_heap_regs->AtomSigWakeUp_
|
#define AtomSigWakeUp Yap_heap_regs->AtomSigWakeUp_
|
||||||
|
Atom AtomSingleton_;
|
||||||
|
#define AtomSingleton Yap_heap_regs->AtomSingleton_
|
||||||
Atom AtomSlash_;
|
Atom AtomSlash_;
|
||||||
#define AtomSlash Yap_heap_regs->AtomSlash_
|
#define AtomSlash Yap_heap_regs->AtomSlash_
|
||||||
Atom AtomSocket_;
|
Atom AtomSocket_;
|
||||||
@ -668,6 +678,8 @@
|
|||||||
#define AtomVBar Yap_heap_regs->AtomVBar_
|
#define AtomVBar Yap_heap_regs->AtomVBar_
|
||||||
Atom AtomVar_;
|
Atom AtomVar_;
|
||||||
#define AtomVar Yap_heap_regs->AtomVar_
|
#define AtomVar Yap_heap_regs->AtomVar_
|
||||||
|
Atom AtomVarBranches_;
|
||||||
|
#define AtomVarBranches Yap_heap_regs->AtomVarBranches_
|
||||||
Atom AtomHiddenVar_;
|
Atom AtomHiddenVar_;
|
||||||
#define AtomHiddenVar Yap_heap_regs->AtomHiddenVar_
|
#define AtomHiddenVar Yap_heap_regs->AtomHiddenVar_
|
||||||
Atom AtomVariable_;
|
Atom AtomVariable_;
|
||||||
|
@ -298,6 +298,7 @@ PLCONS_SOURCES = \
|
|||||||
|
|
||||||
PL_SOURCES= \
|
PL_SOURCES= \
|
||||||
pl/arith.yap \
|
pl/arith.yap \
|
||||||
|
pl/arithpreds.yap \
|
||||||
pl/arrays.yap \
|
pl/arrays.yap \
|
||||||
pl/attributes.yap \
|
pl/attributes.yap \
|
||||||
pl/atoms.yap \
|
pl/atoms.yap \
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
@node Built-ins, Library, Modules, Top
|
@node Built-ins, Library, Modules, Top
|
||||||
|
|
||||||
|
@chapter Built-In Predicates Library
|
||||||
|
|
||||||
@menu
|
@menu
|
||||||
|
|
||||||
Built-ins, Debugging, Syntax, Top
|
Built-ins, Debugging, Syntax, Top
|
||||||
@ -13,7 +15,7 @@ Built-ins, Debugging, Syntax, Top
|
|||||||
* Predicates on Characters:: Manipulating Characters
|
* Predicates on Characters:: Manipulating Characters
|
||||||
* Comparing Terms:: Comparison of Terms
|
* Comparing Terms:: Comparison of Terms
|
||||||
* Arithmetic:: Arithmetic in YAP
|
* Arithmetic:: Arithmetic in YAP
|
||||||
* I/O:: Input/Output with YAP
|
* Input/Output:: Input/Output with YAP
|
||||||
* Database:: Modifying Prolog's Database
|
* Database:: Modifying Prolog's Database
|
||||||
* Sets:: Finding All Possible Solutions
|
* Sets:: Finding All Possible Solutions
|
||||||
* Grammars:: Grammar Rules
|
* Grammars:: Grammar Rules
|
||||||
@ -30,7 +32,7 @@ Built-ins, Debugging, Syntax, Top
|
|||||||
@end menu
|
@end menu
|
||||||
|
|
||||||
@node Control, Undefined Procedures, , Top
|
@node Control, Undefined Procedures, , Top
|
||||||
@chapter Control Predicates
|
@section Control Predicates
|
||||||
|
|
||||||
|
|
||||||
This chapter describes the predicates for controlling the execution of
|
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
|
@end table
|
||||||
|
|
||||||
@node Testing Terms, Predicates on Atoms, Messages, Top
|
@node Testing Terms, Predicates on Atoms, Messages, Top
|
||||||
@chapter Predicates on terms
|
@section Predicates on terms
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
@ -1194,8 +1196,7 @@ the call.
|
|||||||
|
|
||||||
@item digit(@var{Weight})
|
@item digit(@var{Weight})
|
||||||
@var{Char} is a digit with value
|
@var{Char} is a digit with value
|
||||||
@var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X =
|
@var{Weight}. I.e. @code{char_type(X, digit(6))} yields @code{X = '6'}. Useful for parsing numbers.
|
||||||
'6'}. Useful for parsing numbers.
|
|
||||||
|
|
||||||
@item xdigit(@var{Weight})
|
@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.
|
@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
|
@end table
|
||||||
|
|
||||||
@node Arithmetic, I/O, Comparing Terms, Top
|
@node Arithmetic, Input/Output, Comparing Terms, Top
|
||||||
@section Arithmetic
|
@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:
|
YAP now supports several different numeric types:
|
||||||
|
|
||||||
@table @code
|
@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
|
numbers that are returned from is/2 are canonical, which means M
|
||||||
is positive and N and M have no common divisors. Rational numbers
|
is positive and N and M have no common divisors. Rational numbers
|
||||||
are introduced in the computation using the rational/1,
|
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
|
@item float
|
||||||
Floating point numbers are represented using the C-type double. On most today platforms these are 64-bit IEEE floating point numbers.
|
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}.
|
@code{X}.
|
||||||
|
|
||||||
@item @var{X} div @var{Y} [ISO]
|
@item @var{X} div @var{Y} [ISO]
|
||||||
Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y})
|
Integer division, as if defined by @code{(@var{X} - @var{X} mod @var{Y})// @var{Y}}.
|
||||||
// @var{Y}}.
|
|
||||||
|
|
||||||
@item exp(@var{X}) [ISO]
|
@item exp(@var{X}) [ISO]
|
||||||
Natural exponential.
|
Natural exponential.
|
||||||
@ -1767,6 +1780,7 @@ The primitive YAP predicates involving arithmetic expressions are:
|
|||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
|
@itemize
|
||||||
@item @var{X} is +@var{Y} [2]
|
@item @var{X} is +@var{Y} [2]
|
||||||
@findex is/2
|
@findex is/2
|
||||||
@syindex is/2
|
@syindex is/2
|
||||||
@ -1780,6 +1794,7 @@ X is 2+3*4
|
|||||||
@end example
|
@end example
|
||||||
@noindent
|
@noindent
|
||||||
succeeds with @code{X = 14}.
|
succeeds with @code{X = 14}.
|
||||||
|
@end itemize
|
||||||
|
|
||||||
@item +@var{X} < +@var{Y} [ISO]
|
@item +@var{X} < +@var{Y} [ISO]
|
||||||
@findex </2
|
@findex </2
|
||||||
@ -1852,7 +1867,6 @@ will be thrown back to the top-level.
|
|||||||
The following predicates provide counting:
|
The following predicates provide counting:
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
@item between(+@var{Low}, +@var{High}, ?@var{Value})
|
@item between(+@var{Low}, +@var{High}, ?@var{Value})
|
||||||
@findex between/3
|
@findex between/3
|
||||||
@syindex between/3
|
@syindex between/3
|
||||||
@ -1907,13 +1921,16 @@ The following predicates provide counting:
|
|||||||
@cnindex isinf/1
|
@cnindex isinf/1
|
||||||
True if floating point expression @var{Float} evaluates to infinity.
|
True if floating point expression @var{Float} evaluates to infinity.
|
||||||
|
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node I/O, Database, Arithmetic, Top
|
@end texinfo
|
||||||
@chapter I/O Predicates
|
|
||||||
|
|
||||||
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.
|
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
|
If this flag is cleared the same predicates will just fail. Details on
|
||||||
setting and clearing this flag are given under 7.7.
|
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
|
Subnodes of Input/Output
|
||||||
* Streams and Files:: Handling Streams and Files
|
* Streams and Files:: Handling Streams and Files
|
||||||
* C-Prolog File Handling:: C-Prolog Compatible File Handling
|
* C-Prolog File Handling:: C-Prolog Compatible File Handling
|
||||||
* I/O of Terms:: Input/Output of terms
|
* Input/Output of Terms:: Input/Output of terms
|
||||||
* I/O of Characters:: Input/Output of Characters
|
* Input/Output of Characters:: Input/Output of Characters
|
||||||
* I/O for Streams:: Input/Output using Streams
|
* Input/Output for Streams:: Input/Output using Streams
|
||||||
* C-Prolog to Terminal:: C-Prolog compatible Character I/O to terminal
|
* C-Prolog to Terminal:: C-Prolog compatible Character Input/Output to terminal
|
||||||
* I/O Control:: Controlling your Input/Output
|
* Input/Output Control:: Controlling your Input/Output
|
||||||
* Sockets:: Using Sockets from YAP
|
* Sockets:: Using Sockets from YAP
|
||||||
|
|
||||||
@end menu
|
@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
|
@section Handling Streams and Files
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -2002,7 +2019,7 @@ wide character and encoding issues.
|
|||||||
@item representation_errors(+@var{Mode})
|
@item representation_errors(+@var{Mode})
|
||||||
Change the behaviour when writing characters to the stream that cannot
|
Change the behaviour when writing characters to the stream that cannot
|
||||||
be represented by the encoding. The behaviour is one of @code{error}
|
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).
|
escape code or @code{xml} (write @code{&#...;} XML character entity).
|
||||||
The initial mode is @code{prolog} for the user streams and
|
The initial mode is @code{prolog} for the user streams and
|
||||||
@code{error} for all other streams. See also @ref{Encoding}.
|
@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
|
@var{Time}. @var{Time} is a floating point number expressing the seconds
|
||||||
elapsed since Jan 1, 1970.
|
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})
|
@item absolute_file_name(+@var{Name},+@var{Options}, -@var{FullPath}) absolute_file_name(+@var{Name}, -@var{FullPath},+@var{Options})
|
||||||
@findex absolute_file_name/3
|
@findex absolute_file_name/3
|
||||||
@syindex 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},
|
swapped, making the call @code{absolute_file_name}(+@var{Spec}, -@var{Path},
|
||||||
+@var{Options}) valid as well.
|
+@var{Options}) valid as well.
|
||||||
|
|
||||||
|
|
||||||
@item absolute_file_name(+@var{Name},-@var{FullPath})
|
@item absolute_file_name(+@var{Name},-@var{FullPath})
|
||||||
@findex absolute_file_name/2
|
@findex absolute_file_name/2
|
||||||
@syindex 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
|
named @var{Name}. Unify @var{FullPath} with @code{user} if the file
|
||||||
name is @code{user}.
|
name is @code{user}.
|
||||||
|
|
||||||
|
@end texinfo
|
||||||
|
|
||||||
@item file_base_name(+@var{Name},-@var{FileName})
|
@item file_base_name(+@var{Name},-@var{FileName})
|
||||||
@findex file_base_name/2
|
@findex file_base_name/2
|
||||||
@snindex file_base_name/2
|
@snindex file_base_name/2
|
||||||
@ -2297,7 +2323,7 @@ overview of wide character and encoding issues in YAP.
|
|||||||
@item representation_errors(+@var{Mode})
|
@item representation_errors(+@var{Mode})
|
||||||
Behaviour when writing characters to the stream that cannot be
|
Behaviour when writing characters to the stream that cannot be
|
||||||
represented by the encoding. The behaviour is one of @code{error}
|
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).
|
escape code or @code{xml} (write @code{&#...;} XML character entity).
|
||||||
The initial mode is @code{prolog} for the user streams and
|
The initial mode is @code{prolog} for the user streams and
|
||||||
@code{error} for all other streams. See also @ref{Encoding} 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
|
@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
|
@section C-Prolog File Handling
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -2423,7 +2449,8 @@ Closes the current input stream (see 6.7.).
|
|||||||
|
|
||||||
@end table
|
@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
|
@section Handling Input/Output of Terms
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -2859,7 +2886,7 @@ X = [104, 101, 108, 108, 111]
|
|||||||
|
|
||||||
@end table
|
@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
|
@section Handling Input/Output of Characters
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -2988,7 +3015,7 @@ Outputs a new line to the current output stream.
|
|||||||
|
|
||||||
@end table
|
@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
|
@section Input/Output Predicates applied to Streams
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -3154,8 +3181,8 @@ Outputs a new line to stream @var{S}.
|
|||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node C-Prolog to Terminal, I/O Control, I/O for Streams, I/O
|
@node C-Prolog to Terminal, Input/Output Control, Input/Output for Streams, Input/Output
|
||||||
@section Compatible C-Prolog predicates for Terminal I/O
|
@section Compatible C-Prolog predicates for Terminal Input/Output
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
|
|
||||||
@ -3198,7 +3225,7 @@ Outputs a new line to stream @code{user_output}.
|
|||||||
|
|
||||||
@end table
|
@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
|
@section Controlling Input/Output
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -3223,7 +3250,7 @@ opened or closed.
|
|||||||
@syindex fileerrors/0
|
@syindex fileerrors/0
|
||||||
@cyindex fileerrors/0
|
@cyindex fileerrors/0
|
||||||
Switches on the file_errors flag so that in certain error conditions
|
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
|
@item always_prompt_user
|
||||||
@findex always_prompt_user/0
|
@findex always_prompt_user/0
|
||||||
@ -3235,15 +3262,15 @@ interactive control from a pipe or a socket.
|
|||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Sockets, , I/O Control, I/O
|
@node Sockets, , Input/Output Control, Input/Output
|
||||||
@section Using Sockets From YAP
|
@section Using Sockets From YAP
|
||||||
|
|
||||||
YAP includes a SICStus Prolog compatible socket interface. In YAP-6.3
|
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
|
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
|
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
|
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:
|
from sockets. The following calls are available:
|
||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@ -3394,8 +3421,8 @@ address in number and dots notation.
|
|||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Database, Sets, I/O, Top
|
@node Database, Sets, Input/Output, Top
|
||||||
@chapter Using the Clausal Data Base
|
@section Using the Clausal Data Base
|
||||||
|
|
||||||
Predicates in YAP may be dynamic or static. By default, when
|
Predicates in YAP may be dynamic or static. By default, when
|
||||||
consulting or reconsulting, predicates are assumed to be static:
|
consulting or reconsulting, predicates are assumed to be static:
|
||||||
@ -4204,7 +4231,7 @@ no
|
|||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Grammars, OS, Sets, Top
|
@node Grammars, OS, Sets, Top
|
||||||
@chapter Grammar Rules
|
@section Grammar Rules
|
||||||
|
|
||||||
Grammar rules in Prolog are both a convenient way to express definite
|
Grammar rules in Prolog are both a convenient way to express definite
|
||||||
clause grammars and an extension of the well known context-free grammars.
|
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
|
@end table
|
||||||
|
|
||||||
@node OS, Term Modification, Grammars, Top
|
@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
|
The following built-in predicates allow access to underlying
|
||||||
Operating System functionality:
|
Operating System functionality:
|
||||||
@ -4548,7 +4575,7 @@ order of dispatch.
|
|||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Term Modification, Global Variables, OS, Top
|
@node Term Modification, Global Variables, OS, Top
|
||||||
@chapter Term Modification
|
@section Term Modification
|
||||||
|
|
||||||
@cindex updating terms
|
@cindex updating terms
|
||||||
It is sometimes useful to change the value of instantiated
|
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
|
@end table
|
||||||
|
|
||||||
@node Global Variables, Profiling, Term Modification, Top
|
@node Global Variables, Profiling, Term Modification, Top
|
||||||
@chapter Global Variables
|
@section Global Variables
|
||||||
|
|
||||||
@cindex global variables
|
@cindex global variables
|
||||||
|
|
||||||
@ -4804,7 +4831,7 @@ compound terms.
|
|||||||
|
|
||||||
|
|
||||||
@node Profiling, Call Counting, Global Variables, Top
|
@node Profiling, Call Counting, Global Variables, Top
|
||||||
@chapter Profiling Prolog Programs
|
@section Profiling Prolog Programs
|
||||||
|
|
||||||
@cindex profiling
|
@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.
|
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
|
@node Call Counting, Arrays, Profiling, Top
|
||||||
@chapter Counting Calls
|
@section Counting Calls
|
||||||
|
|
||||||
@cindex Counting Calls
|
@cindex Counting Calls
|
||||||
Predicates compiled with YAP's flag @code{call_counting} set to
|
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
|
@node Arrays, Preds, Call Counting , Top
|
||||||
@chapter Arrays
|
@section Arrays
|
||||||
|
|
||||||
The YAP system includes experimental support for arrays. The
|
The YAP system includes experimental support for arrays. The
|
||||||
support is enabled with the option @code{YAP_ARRAYS}.
|
support is enabled with the option @code{YAP_ARRAYS}.
|
||||||
@ -5223,7 +5250,7 @@ terms.
|
|||||||
@end table
|
@end table
|
||||||
|
|
||||||
@node Preds, Misc, Arrays, Top
|
@node Preds, Misc, Arrays, Top
|
||||||
@chapter Predicate Information
|
@section Predicate Information
|
||||||
|
|
||||||
Built-ins that return information on the current predicates and modules:
|
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
|
@end table
|
||||||
|
|
||||||
@node Misc, , Preds, Top
|
@node Misc, , Preds, Top
|
||||||
@chapter Miscellaneous
|
@section Miscellaneous
|
||||||
|
|
||||||
@table @code
|
@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
|
Size of static code in YAP in bytes: @var{Clause Size}, the number of
|
||||||
bytes allocated for clauses, plus
|
bytes allocated for clauses, plus
|
||||||
@var{Index Size}, the number of bytes spent in the indexing code. The
|
@var{Index Size}, the number of bytes spent in the indexing code. The
|
||||||
indexing code is divided into main tree, @var{Tree Index
|
indexing code is divided into main tree, @var{Tree Index Size},
|
||||||
Size}, tables that implement choice-point manipulation, @var{Choice Point Instructions
|
tables that implement choice-point manipulation, @var{Choice xsPoint Instructions Size}, tables that cache clauses for future expansion of the index
|
||||||
Size}, tables that cache clauses for future expansion of the index
|
|
||||||
tree, @var{Expansion Nodes Size}, and
|
tree, @var{Expansion Nodes Size}, and
|
||||||
tables such as hash tables that select according to value, @var{Index Switch Size}.
|
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
|
Size of static code in YAP in bytes: @var{Clause Size}, the number of
|
||||||
bytes allocated for clauses, plus
|
bytes allocated for clauses, plus
|
||||||
@var{Index Size}, the number of bytes spent in the indexing code. The
|
@var{Index Size}, the number of bytes spent in the indexing code. The
|
||||||
indexing code is divided into a main tree, @var{Tree Index
|
indexing code is divided into a main tree, @var{Tree Index Size}, table that cache clauses for future expansion of the index
|
||||||
Size}, table that cache clauses for future expansion of the index
|
|
||||||
tree, @var{Expansion Nodes Size}, and and
|
tree, @var{Expansion Nodes Size}, and and
|
||||||
tables such as hash tables that select according to value, @var{Index Switch Size}.
|
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
|
consulting files. If @code{false} disable printing these messages. It
|
||||||
is @code{normal} by default except if YAP is booted with the @code{-L}
|
is @code{normal} by default except if YAP is booted with the @code{-L}
|
||||||
flag.
|
flag.
|
||||||
.
|
|
||||||
|
|
||||||
@item version
|
@item version
|
||||||
@findex version (yap_flag/2 option)
|
@findex version (yap_flag/2 option)
|
||||||
@ -6058,7 +6082,7 @@ filed are ignored.
|
|||||||
Current source module.
|
Current source module.
|
||||||
|
|
||||||
@item source (prolog_load_context/2 option)
|
@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,
|
Full name for the file currently being read in, which may be consulted,
|
||||||
reconsulted, or included.
|
reconsulted, or included.
|
||||||
|
@ -51,14 +51,14 @@ PROJECT_BRIEF =
|
|||||||
# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
|
# and the maximum width should not exceed 200 pixels. Doxygen will copy the logo
|
||||||
# to the output directory.
|
# 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
|
# 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
|
# 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
|
# entered, it will be relative to the location where doxygen was started. If
|
||||||
# left blank the current directory will be used.
|
# 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-
|
# 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
|
# 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.
|
# performance problems for the file system.
|
||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
|
|
||||||
CREATE_SUBDIRS = NO
|
CREATE_SUBDIRS = YES
|
||||||
|
|
||||||
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
|
# The OUTPUT_LANGUAGE tag is used to specify the language in which all
|
||||||
# documentation generated by doxygen is written. Doxygen will use this
|
# 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
|
# "Side Effects:". You can put \n's in the value part of an alias to insert
|
||||||
# newlines.
|
# 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).
|
# 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"
|
# A mapping has the form "name=value". For example adding "class=itcl::class"
|
||||||
@ -244,7 +249,9 @@ TCL_SUBST =
|
|||||||
# members will be omitted, etc.
|
# members will be omitted, etc.
|
||||||
# The default value is: NO.
|
# 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
|
# 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
|
# 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
|
# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
|
||||||
# the files are not read by doxygen.
|
# 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
|
# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
|
||||||
# according to the Markdown format, which allows for more readable
|
# 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
|
# search path. Do not use file names with spaces, bibtex cannot handle them. See
|
||||||
# also \cite for info how to create references.
|
# 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
|
# Configuration options related to warning and progress messages
|
||||||
@ -753,7 +760,7 @@ WARN_LOGFILE =
|
|||||||
# spaces.
|
# spaces.
|
||||||
# Note: If this tag is empty the current directory is searched.
|
# 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
|
# 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
|
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||||
@ -788,6 +795,7 @@ FILE_PATTERNS = *.c \
|
|||||||
*.ddl \
|
*.ddl \
|
||||||
*.odl \
|
*.odl \
|
||||||
*.h \
|
*.h \
|
||||||
|
*.h.in \
|
||||||
*.hh \
|
*.hh \
|
||||||
*.hxx \
|
*.hxx \
|
||||||
*.hpp \
|
*.hpp \
|
||||||
@ -814,7 +822,9 @@ FILE_PATTERNS = *.c \
|
|||||||
*.ucf \
|
*.ucf \
|
||||||
*.qsf \
|
*.qsf \
|
||||||
*.as \
|
*.as \
|
||||||
*.js
|
*.js \
|
||||||
|
*.pl \
|
||||||
|
*.yap
|
||||||
|
|
||||||
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
# The RECURSIVE tag can be used to specify whether or not subdirectories should
|
||||||
# be searched for input files as well.
|
# 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
|
# (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.
|
# 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
|
# Configuration options related to source browsing
|
||||||
@ -949,7 +959,7 @@ SOURCE_BROWSER = YES
|
|||||||
# classes and enums directly into the documentation.
|
# classes and enums directly into the documentation.
|
||||||
# The default value is: NO.
|
# 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
|
# 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
|
# special comment blocks from generated source code fragments. Normal C, C++ and
|
||||||
@ -1422,7 +1432,7 @@ DISABLE_INDEX = NO
|
|||||||
# The default value is: NO.
|
# The default value is: NO.
|
||||||
# This tag requires that the tag GENERATE_HTML is set to YES.
|
# 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
|
# 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.
|
# 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
|
@end table
|
||||||
|
|
||||||
@node Setting the Compiler, Conditional Compilation, Compiling, Loading Programs
|
@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
|
@section Changing the Compiler's Behavior
|
||||||
|
|
||||||
This section presents a set of built-ins predicates designed to set the
|
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
|
@code{do_not_compile_expressions}. This predicate was kept to maintain
|
||||||
compatibility with C-Prolog.
|
compatibility with C-Prolog.
|
||||||
|
|
||||||
|
@texinfo
|
||||||
|
|
||||||
@item path(-@var{D})
|
@item path(-@var{D})
|
||||||
@findex path/1
|
@findex path/1
|
||||||
@snindex 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
|
@cnindex remove_from_path/1
|
||||||
Remove @var{D} from YAP's directory search path.
|
Remove @var{D} from YAP's directory search path.
|
||||||
|
|
||||||
|
@end texinfo
|
||||||
|
|
||||||
@item style_check(+@var{X})
|
@item style_check(+@var{X})
|
||||||
@findex style_check/1
|
@findex style_check/1
|
||||||
@snindex 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).
|
restoring a state (not implemented yet).
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
|
@texinfo
|
||||||
|
|
||||||
@item library_directory(+@var{D})
|
@item library_directory(+@var{D})
|
||||||
@findex library_directory/1
|
@findex library_directory/1
|
||||||
@snindex 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
|
@findex file_search_path/2
|
||||||
@syindex file_search_path/2
|
@syindex file_search_path/2
|
||||||
@cnindex 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
|
@var{DIRECTORY} must be atoms. The predicate may generate multiple
|
||||||
solutions. The predicate is originally defined as follows:
|
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
|
Unify @var{FullPath} with the absolute path YAP would use to consult
|
||||||
file @var{Name}.
|
file @var{Name}.
|
||||||
|
|
||||||
|
@end texinfo
|
||||||
|
|
||||||
@item prolog_to_os_filename(+@var{PrologPath},-@var{OsPath})
|
@item prolog_to_os_filename(+@var{PrologPath},-@var{OsPath})
|
||||||
@findex prolog_to_os_filename/2
|
@findex prolog_to_os_filename/2
|
||||||
@snindex 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
|
@table @code
|
||||||
|
|
||||||
@item append(?@var{List1},?@var{List2},?@var{List3})
|
@item append(?@var{List1},?@var{List2},?@var{List3})
|
||||||
@findex append/3
|
@findex swi_append/3
|
||||||
@snindex append/3
|
@snindex swi_append/3
|
||||||
@cnindex append/3
|
@cnindex swi_append/3
|
||||||
Succeeds when @var{List3} unifies with the concatenation of @var{List1}
|
Succeeds when @var{List3} unifies with the concatenation of @var{List1}
|
||||||
and @var{List2}. The predicate can be used with any instantiation
|
and @var{List2}. The predicate can be used with any instantiation
|
||||||
pattern (even three variables).
|
pattern (even three variables).
|
||||||
|
|
||||||
@item between(+@var{Low},+@var{High},?@var{Value})
|
@item between(+@var{Low},+@var{High},?@var{Value})
|
||||||
@findex between/3
|
@findex swi_between/3
|
||||||
@snindex between/3
|
@snindex swi_between/3
|
||||||
@cnindex between/3
|
@cnindex swi_between/3
|
||||||
|
|
||||||
@var{Low} and @var{High} are integers, @var{High} less or equal than
|
@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
|
@var{Low}. If @var{Value} is an integer, @var{Low} less or equal than
|
||||||
@ -67,9 +67,9 @@ L = [gnu, gnat]
|
|||||||
@end example
|
@end example
|
||||||
|
|
||||||
@item nth1(+@var{Index},?@var{List},?@var{Elem})
|
@item nth1(+@var{Index},?@var{List},?@var{Elem})
|
||||||
@findex nth1/3
|
@findex swi_nth1/3
|
||||||
@snindex nth1/3
|
@snindex swi_nth1/3
|
||||||
@cnindex nth1/3
|
@cnindex swi_nth1/3
|
||||||
Succeeds when the @var{Index}-th element of @var{List} unifies with
|
Succeeds when the @var{Index}-th element of @var{List} unifies with
|
||||||
@var{Elem}. Counting starts at 1.
|
@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}.
|
They also influence @code{expand_file_name/2}.
|
||||||
|
|
||||||
@item setenv(+@var{Name},+@var{Value})
|
@item setenv(+@var{Name},+@var{Value})
|
||||||
@findex setenv/2
|
@findex swi_setenv/2
|
||||||
@snindex setenv/2
|
@snindex swi_setenv/2
|
||||||
@cnindex setenv/2
|
@cnindex swi_setenv/2
|
||||||
Set environment variable. @var{Name} and @var{Value} should be
|
Set environment variable. @var{Name} and @var{Value} should be
|
||||||
instantiated to atoms or integers. The environment variable will 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}.
|
passed to @code{shell/[0-2]} and can be requested using @code{getenv/2}.
|
||||||
They also influence @code{expand_file_name/2}.
|
They also influence @code{expand_file_name/2}.
|
||||||
|
|
||||||
@item term_to_atom(?@var{Term},?@var{Atom})
|
@item term_to_atom(?@var{Term},?@var{Atom})
|
||||||
@findex term_to_atom/2
|
@findex swi_term_to_atom/2
|
||||||
@snindex term_to_atom/2
|
@snindex swi_term_to_atom/2
|
||||||
@cnindex term_to_atom/2
|
@cnindex swi_term_to_atom/2
|
||||||
Succeeds if @var{Atom} describes a term that unifies with @var{Term}. When
|
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{Atom} is instantiated @var{Atom} is converted and then unified with
|
||||||
@var{Term}. If @var{Atom} has no valid syntax, a @code{syntax_error}
|
@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}.
|
using @code{write/1}.
|
||||||
|
|
||||||
@item working_directory(-@var{Old},+@var{New})
|
@item working_directory(-@var{Old},+@var{New})
|
||||||
@findex working_directory/2
|
@findex swi_working_directory/2
|
||||||
@snindex working_directory/2
|
@snindex swi_working_directory/2
|
||||||
@cnindex working_directory/2
|
@cnindex swi_working_directory/2
|
||||||
|
|
||||||
Unify @var{Old} with an absolute path to the current working directory
|
Unify @var{Old} with an absolute path to the current working directory
|
||||||
and change working directory to @var{New}. Use the pattern
|
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
|
@table @code
|
||||||
|
|
||||||
@item maplist(+@var{Pred},+@var{List})
|
@item maplist(+@var{Pred},+@var{List})
|
||||||
@findex maplist/2
|
@findex swi_maplist/2
|
||||||
@snindex maplist/2
|
@snindex swi_maplist/2
|
||||||
@cnindex maplist/2
|
@cnindex swi_maplist/2
|
||||||
@var{Pred} is applied successively on each element of @var{List} until
|
@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
|
the end of the list or @var{Pred} fails. In the latter case
|
||||||
@code{maplist/2} fails.
|
@code{maplist/2} fails.
|
||||||
|
|
||||||
@item maplist(+@var{Pred},+@var{List1},+@var{List2})
|
@item maplist(+@var{Pred},+@var{List1},+@var{List2})
|
||||||
@findex maplist/3
|
@findex swi_maplist/3
|
||||||
@snindex maplist/3
|
@snindex swi_maplist/3
|
||||||
@cnindex maplist/3
|
@cnindex swi_maplist/3
|
||||||
Apply @var{Pred} on all successive pairs of elements from
|
Apply @var{Pred} on all successive pairs of elements from
|
||||||
@var{List1} and
|
@var{List1} and
|
||||||
@var{List2}. Fails if @var{Pred} can not be applied to a
|
@var{List2}. Fails if @var{Pred} can not be applied to a
|
||||||
pair. See the example above.
|
pair. See the example above.
|
||||||
|
|
||||||
@item maplist(+@var{Pred},+@var{List1},+@var{List2},+@var{List4})
|
@item maplist(+@var{Pred},+@var{List1},+@var{List2},+@var{List4})
|
||||||
@findex maplist/4
|
@findex swi_maplist/4
|
||||||
@snindex maplist/4
|
@snindex swi_maplist/4
|
||||||
@cnindex maplist/4
|
@cnindex swi_maplist/4
|
||||||
Apply @var{Pred} on all successive triples of elements from @var{List1},
|
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
|
@var{List2} and @var{List3}. Fails if @var{Pred} can not be applied to a
|
||||||
triple. See the example above.
|
triple. See the example above.
|
||||||
@ -174,9 +174,10 @@ triple. See the example above.
|
|||||||
|
|
||||||
@table @code
|
@table @code
|
||||||
@item forall(+@var{Cond},+@var{Action})
|
@item forall(+@var{Cond},+@var{Action})
|
||||||
@findex forall/2
|
@findex swi_forall/2
|
||||||
@snindex forall/2
|
@snindex swi_forall/2
|
||||||
@cnindex forall/2
|
@snindex swi_forall/2
|
||||||
|
@cnindex swi_forall/2
|
||||||
|
|
||||||
For all alternative bindings of @var{Cond} @var{Action} can be proven.
|
For all alternative bindings of @var{Cond} @var{Action} can be proven.
|
||||||
The next example verifies that all arithmetic statements in the list
|
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
|
@table @code
|
||||||
@item b_setval(+@var{Name},+@var{Value})
|
@item b_setval(+@var{Name},+@var{Value})
|
||||||
@findex b_setval/2
|
@findex swi_b_setval/2
|
||||||
@snindex b_setval/2
|
@snindex swi_b_setval/2
|
||||||
@cnindex b_setval/2
|
@cnindex swi_b_setval/2
|
||||||
Associate the term @var{Value} with the atom @var{Name} or replaces
|
Associate the term @var{Value} with the atom @var{Name} or replaces
|
||||||
the currently associated value with @var{Value}. If @var{Name} does
|
the currently associated value with @var{Value}. If @var{Name} does
|
||||||
not refer to an existing global variable a variable with initial value
|
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.
|
assignment is reversed.
|
||||||
|
|
||||||
@item b_getval(+@var{Name},-@var{Value})
|
@item b_getval(+@var{Name},-@var{Value})
|
||||||
@findex b_getval/2
|
@findex swi_b_getval/2
|
||||||
@snindex b_getval/2
|
@snindex swi_b_getval/2
|
||||||
@cnindex b_getval/2
|
@cnindex swi_b_getval/2
|
||||||
Get the value associated with the global variable @var{Name} and unify
|
Get the value associated with the global variable @var{Name} and unify
|
||||||
it with @var{Value}. Note that this unification may further instantiate
|
it with @var{Value}. Note that this unification may further instantiate
|
||||||
the value of the global variable. If this is undesirable the normal
|
the value of the global variable. If this is undesirable the normal
|
||||||
precautions (double negation or @code{copy_term/2}) must be taken. The
|
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
|
@code{b_getval/2} predicate generates errors if @var{Name} is not an atom or
|
||||||
the requested variable does not exist.
|
the requested variable does not exist.
|
||||||
@end table
|
|
||||||
|
|
||||||
@table @code
|
|
||||||
|
|
||||||
@item nb_setval(+@var{Name},+@var{Value})
|
@item nb_setval(+@var{Name},+@var{Value})
|
||||||
@findex nb_setval/2
|
@findex swi_nb_setval/2
|
||||||
@snindex nb_setval/2
|
@snindex swi_nb_setval/2
|
||||||
@cnindex nb_setval/2
|
@cnindex swi_nb_setval/2
|
||||||
Associates a copy of @var{Value} created with @code{duplicate_term/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
|
with the atom @var{Name}. Note that this can be used to set an
|
||||||
initial value other than @code{[]} prior to backtrackable assignment.
|
initial value other than @code{[]} prior to backtrackable assignment.
|
||||||
|
|
||||||
@item nb_getval(+@var{Name},-@var{Value})
|
@item nb_getval(+@var{Name},-@var{Value})
|
||||||
@findex nb_getval/2
|
@findex swi_nb_getval/2
|
||||||
@snindex nb_getval/2
|
@snindex swi_nb_getval/2
|
||||||
@cnindex nb_getval/2
|
@cnindex swi_nb_getval/2
|
||||||
The @code{nb_getval/2} predicate is a synonym for b_getval/2, introduced for
|
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
|
compatibility and symmetry. As most scenarios will use a particular
|
||||||
global variable either using non-backtrackable or backtrackable
|
global variable either using non-backtrackable or backtrackable
|
||||||
@ -297,9 +295,9 @@ variable is used non-backtrackable.
|
|||||||
@c \end{code}
|
@c \end{code}
|
||||||
|
|
||||||
@item nb_current(?@var{Name},?@var{Value})
|
@item nb_current(?@var{Name},?@var{Value})
|
||||||
@findex nb_current/2
|
@findex swi_nb_current/2
|
||||||
@snindex nb_current/2
|
@snindex swi_nb_current/2
|
||||||
@cnindex nb_current/2
|
@cnindex swi_nb_current/2
|
||||||
Enumerate all defined variables with their value. The order of
|
Enumerate all defined variables with their value. The order of
|
||||||
enumeration is undefined.
|
enumeration is undefined.
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ scan_file( Inp ) :-
|
|||||||
repeat,
|
repeat,
|
||||||
line_count( S, Lines ),
|
line_count( S, Lines ),
|
||||||
read_line_to_string(S, Line0),
|
read_line_to_string(S, Line0),
|
||||||
%( Lines = 416 %string(Line0),sub_string( Line0,_,_,_, "\secref{unicodesyntax}") -> trace ; true ),
|
|
||||||
assert_static( source( Inp, Lines, Line0 ) ),
|
assert_static( source( Inp, Lines, Line0 ) ),
|
||||||
( Line0 == end_of_file ->
|
( Line0 == end_of_file ->
|
||||||
!,
|
!,
|
||||||
@ -131,7 +130,9 @@ out( _S ) :-
|
|||||||
nb_setval( min, 0 ),
|
nb_setval( min, 0 ),
|
||||||
fail.
|
fail.
|
||||||
out( S ) :-
|
out( S ) :-
|
||||||
line( F, Pos, Line),
|
line( F, Pos, Line0),
|
||||||
|
%( Pos = 5770 -> trace ; true ),
|
||||||
|
jmp_blanks( Line0, Line),
|
||||||
b_setval( line, F:Pos:Line ),
|
b_setval( line, F:Pos:Line ),
|
||||||
process( Line , NewLine, F:Pos),
|
process( Line , NewLine, F:Pos),
|
||||||
offset( N ),
|
offset( N ),
|
||||||
@ -141,8 +142,8 @@ out( S ) :-
|
|||||||
;
|
;
|
||||||
NewLine == ""
|
NewLine == ""
|
||||||
->
|
->
|
||||||
% nb_getval( old_line, OldLine ),
|
nb_getval( old_line, OldLine ),
|
||||||
% OldLine \= "",
|
OldLine \= "",
|
||||||
format(string(SN), '~n', [])
|
format(string(SN), '~n', [])
|
||||||
;
|
;
|
||||||
NewLine == force
|
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("@enumerate",_R,L), !.
|
||||||
singleton_line(L) :- string_concat("@table",_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("@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("@simpleexample",_R,L), !, assert( singletons ).
|
||||||
singleton_line(L) :- string_concat("@end",R,L), !,
|
singleton_line(L) :- string_concat("@end",R,L), !,
|
||||||
( sub_string(R, _, _, _, "example") -> retract( singletons ) ; true ).
|
( sub_string(R, _, _, _, "example") -> retract( singletons ) ; true ).
|
||||||
@ -200,16 +204,20 @@ process( Line , S, F:Pos ) :-
|
|||||||
(
|
(
|
||||||
first_word(Line, "@end", Rest)
|
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 = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
|
( S = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" ;
|
||||||
pop( skip, verbatim ), fail
|
pop( skip, verbatim ), fail
|
||||||
)
|
)
|
||||||
% fail in other ends
|
;
|
||||||
% ;
|
first_word(Rest, Env1, _Rest2),
|
||||||
% Env1 = "cartouche"
|
sub_string( Env1, _, _, 0, "plaintext" )
|
||||||
|
->
|
||||||
|
( S = "" ;
|
||||||
|
pop( skip, verbatim ), fail
|
||||||
|
)
|
||||||
)
|
)
|
||||||
;
|
;
|
||||||
first_word(Line, "@cartouche", Rest)
|
first_word(Line, "@cartouche", Rest)
|
||||||
@ -224,8 +232,12 @@ process( Line , "", _Pos ) :-
|
|||||||
first_word(Line, Word, Rest),
|
first_word(Line, Word, Rest),
|
||||||
Word == "@end",
|
Word == "@end",
|
||||||
first_word(Rest, Word2, _Rest),
|
first_word(Rest, Word2, _Rest),
|
||||||
W2 = Word2,
|
( W2 = Word2
|
||||||
pop( skip, W2 ).
|
->
|
||||||
|
pop( skip, W2 )
|
||||||
|
;
|
||||||
|
true
|
||||||
|
).
|
||||||
% command: flush and continue
|
% command: flush and continue
|
||||||
process( Command , NewLine , Pos) :-
|
process( Command , NewLine , Pos) :-
|
||||||
do_buffer(Command, NewLine, Pos ).
|
do_buffer(Command, NewLine, Pos ).
|
||||||
@ -254,36 +266,49 @@ command( Line, Word, Rest ) :-
|
|||||||
clause( process( Word, _, _, _, _ ), _),
|
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) :-
|
process("@item", Line, Rest, NewLine , FilePos) :-
|
||||||
pop( list, it(Env, Item, Pos, Numb)), !,
|
pop( list, it(Env, Item, Pos, Numb)), !,
|
||||||
NNumb is Numb+1,
|
NNumb is Numb+1,
|
||||||
run( Text, Rest ),
|
run( Text, Rest ),
|
||||||
jmp_blanks( Rest, First ),
|
jmp_blanks( Text, First ),
|
||||||
item_type(Item, Numb, Marker ),
|
Pos1 is Pos,
|
||||||
|
% item_type(Item, Numb, Marker ),
|
||||||
|
Marker = "",
|
||||||
(
|
(
|
||||||
Env = "table",
|
Env = "@table",
|
||||||
atom_string( A, Line ),
|
atom_string( A, Line ),
|
||||||
pred( _Pred, Key, A, FilePos )
|
pred( _Pred, Key, A, FilePos )
|
||||||
->
|
->
|
||||||
push( list, it(Env, Item, Pos, NNumb) ),
|
push( list, it(Env, Item, Pos, NNumb) ),
|
||||||
(
|
(
|
||||||
% sendout the comand
|
% 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 )
|
push( indent, done )
|
||||||
;
|
;
|
||||||
NewLine = force
|
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( list, it(Env, Item, Pos, NNumb) ),
|
||||||
push( indent, done )
|
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) :-
|
process("@end", _Line, Rest, NewLine , _Pos) :-
|
||||||
speek(list,it(Env,_,_LL,_)),
|
speek(list,it(Env,_,_LL,_)),
|
||||||
|
( Env = "@enumerate" ->
|
||||||
|
NewLine = "</ol>"
|
||||||
|
;
|
||||||
|
NewLine = "</ul>"
|
||||||
|
),
|
||||||
sub_string( Env, 1, _, 0, Env1 ),
|
sub_string( Env, 1, _, 0, Env1 ),
|
||||||
sub_string( Rest, _, _, _, Env1), !, % check
|
sub_string( Rest, _, _, _, Env1), !, % check
|
||||||
pop( list, it(Env, _, _, _) ),
|
% writeln(_Pos:_Line), listing(stack),
|
||||||
NewLine = "".
|
pop( list, it(Env, _, _, _) ).
|
||||||
process("@end", Line, _Rest, NewLine , _Pos) :-
|
process("@end", Line, _Rest, NewLine , _Pos) :-
|
||||||
sub_string(Line, _, _, 0, "ifnottex"), !, % check
|
sub_string(Line, _, _, 0, "ifnottex"), !, % check
|
||||||
NewLine = "\\endhtmlonly".
|
NewLine = "\\endhtmlonly".
|
||||||
@ -304,7 +329,11 @@ process("@end", Line, _Rest, NewLine , _Pos) :-
|
|||||||
process("@author", _Line, Rest, NewLine , _Pos) :- !,
|
process("@author", _Line, Rest, NewLine , _Pos) :- !,
|
||||||
jmp_blanks( Rest, Firs ),
|
jmp_blanks( Rest, Firs ),
|
||||||
format( string( NewLine), '\\author ~s', [ 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) :- !,
|
process("@c", _Line, Rest, NewLine , _Pos) :- !,
|
||||||
gen_comment( Rest, NewLine ).
|
gen_comment( Rest, NewLine ).
|
||||||
process("@comment", _Line, Rest, NewLine , _Pos) :- !,
|
process("@comment", _Line, Rest, NewLine , _Pos) :- !,
|
||||||
@ -320,7 +349,8 @@ process("@chapter", _Line, Rest, NewLine, _Pos ) :- !,
|
|||||||
run( Title, Firs ),
|
run( Title, Firs ),
|
||||||
nb_setval( level, 1 ),
|
nb_setval( level, 1 ),
|
||||||
title_from_words(Firs, Id, _Pos),
|
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 = "======" ).
|
% ( format( string(NewLine), '~s', [Title] ) ; NewLine = "======" ).
|
||||||
process("@cindex", _Line, _Rest, no , _Pos) :- !.
|
process("@cindex", _Line, _Rest, no , _Pos) :- !.
|
||||||
process("@caindex", _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 ) :- !,
|
process("@direntry", Line, _Rest, NewLine, _Pos ) :- !,
|
||||||
gen_comment( Line, NewLine ),
|
gen_comment( Line, NewLine ),
|
||||||
push(skip, "direntry" ).
|
push(skip, "direntry" ).
|
||||||
|
process("@texinfo", Line, _Rest, NewLine, _Pos ) :- !,
|
||||||
|
gen_comment( Line, NewLine ),
|
||||||
|
push(skip, "texinfo" ).
|
||||||
process("@documentencoding", _Line, _Rest, "" , _Pos) :- !.
|
process("@documentencoding", _Line, _Rest, "" , _Pos) :- !.
|
||||||
% jmp_blanks( Rest, NewString ),
|
% jmp_blanks( Rest, NewString ),
|
||||||
% format( string( NewLine), '<meta charset="~s">', [ 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).
|
||||||
process("@example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !,
|
process("@example", _Line, _Rest, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" , _Pos) :- !,
|
||||||
push( skip, verbatim).
|
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("@format", _Line, _Rest, "", _Pos ) :- !.
|
||||||
|
process("@alias", _Line, _Rest, "", _Pos ) :- !.
|
||||||
process("@dircategory", _Line, _Rest, "", _Pos ) :- !.
|
process("@dircategory", _Line, _Rest, "", _Pos ) :- !.
|
||||||
process("@smallexample", _Line, _Rest, "" , _Pos).
|
process("@smallexample", _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 ),
|
run( NewTitle, Title ),
|
||||||
nb_setval( level, 2 ),
|
nb_setval( level, 2 ),
|
||||||
% format(string(NewLine), '# ~s #', [NewTitle]).
|
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||||
|
title( '@section', _, TitleDox ),
|
||||||
title_from_words(NewTitle, Id, Pos),
|
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]).
|
% format(string(NewLine), '# ~s #', [NewTitle]).
|
||||||
process("@appendix", _Line, Rest, NewLine, _Pos ) :- !,
|
process("@appendix", _Line, Rest, NewLine, _Pos ) :- !,
|
||||||
jmp_blanks( Rest, Title ),
|
jmp_blanks( Rest, Title ),
|
||||||
@ -384,8 +427,9 @@ process("@subsection", _Line, Rest, NewLine, _Pos ) :- !,
|
|||||||
jmp_blanks( Rest, Title ),
|
jmp_blanks( Rest, Title ),
|
||||||
run( NewTitle, Title ),
|
run( NewTitle, Title ),
|
||||||
nb_setval( level, 3 ),
|
nb_setval( level, 3 ),
|
||||||
|
title( '@subsection', _, TitleDox ),
|
||||||
title_from_words(NewTitle, Id, _Pos),
|
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]).
|
% format(string(NewLine), '## ~s ##', [NewTitle]).
|
||||||
process("@unnumberedsubsubsec", _Line, Rest, NewLine, _Pos ) :- !,
|
process("@unnumberedsubsubsec", _Line, Rest, NewLine, _Pos ) :- !,
|
||||||
nb_setval( level, 4 ),
|
nb_setval( level, 4 ),
|
||||||
@ -394,8 +438,9 @@ process("@subsubsection", _Line, Rest, NewLine, _Pos ) :- !,
|
|||||||
nb_setval( level, 4 ),
|
nb_setval( level, 4 ),
|
||||||
jmp_blanks( Rest, Title ),
|
jmp_blanks( Rest, Title ),
|
||||||
run( NewTitle, Title ),
|
run( NewTitle, Title ),
|
||||||
|
title( '@subsubsection', _, TitleDox ),
|
||||||
title_from_words(NewTitle, Id, _Pos),
|
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]).
|
% format(string(NewLine), '### ~s ###', [NewTitle]).
|
||||||
process("@set", _Line, Rest, NewLine , _Pos) :- !,
|
process("@set", _Line, Rest, NewLine , _Pos) :- !,
|
||||||
first_word( Rest, V, SecC),
|
first_word( Rest, V, SecC),
|
||||||
@ -416,16 +461,7 @@ process("@setchapternewpage", Line, _Rest, NewLine, _Pos ) :- !,
|
|||||||
gen_comment( Line, NewLine ).
|
gen_comment( Line, NewLine ).
|
||||||
process("@setfilename", Line, _Rest, NewLine, _Pos ) :- !,
|
process("@setfilename", Line, _Rest, NewLine, _Pos ) :- !,
|
||||||
gen_comment( Line, NewLine ).
|
gen_comment( Line, NewLine ).
|
||||||
process("@settitle", _Line, Rest, NewLine , _Pos) :- !,
|
process("@settitle", _Line, _Rest, "" , _Pos) :- !.
|
||||||
jmp_blanks( Rest, Title ),
|
|
||||||
( format(string(NewLine), '~s {#mainpage}', [Title]) ; NewLine = "=================="; NewLine = "" ;
|
|
||||||
NewLine = "";
|
|
||||||
NewLine = "[TOC]";
|
|
||||||
NewLine = "";
|
|
||||||
NewLine = "@secreflist" ;
|
|
||||||
NewLine = "";
|
|
||||||
NewLine = "@endsecreflist"
|
|
||||||
).
|
|
||||||
process("@subtitle", _Line, _Rest, "", _Pos ) :- !.
|
process("@subtitle", _Line, _Rest, "", _Pos ) :- !.
|
||||||
process("@include", _Line, _Rest, "", _Pos ) :- !.
|
process("@include", _Line, _Rest, "", _Pos ) :- !.
|
||||||
process("@table", _Line, Rest, NewLine , _Pos) :- !,
|
process("@table", _Line, Rest, NewLine , _Pos) :- !,
|
||||||
@ -461,21 +497,25 @@ get_second( Rest, Title ) :-
|
|||||||
% clear the buffer first.
|
% clear the buffer first.
|
||||||
%
|
%
|
||||||
list( Env, Line, New, _Pos) :-
|
list( Env, Line, New, _Pos) :-
|
||||||
writeln(_Pos),
|
|
||||||
first_word( Line, V, Rest),
|
first_word( Line, V, Rest),
|
||||||
jmp_blanks( Rest, End ),
|
jmp_blanks( Rest, End ),
|
||||||
(
|
(
|
||||||
speek( list, it(_, _,Pos, _) ) ->
|
speek( list, it(_, _, _Pos, _) ) ->
|
||||||
Pos1 is Pos + 6
|
Pos1 is 0 % Pos + 4
|
||||||
;
|
;
|
||||||
Pos1 = 6
|
Pos1 = 0 %4
|
||||||
),
|
),
|
||||||
push( list, it( Env, V, Pos1, 1 ) ),
|
push( list, it( Env, V, Pos1, 1 ) ),
|
||||||
% b_getval( pos, _Pos ),
|
% b_getval( pos, _Pos ),
|
||||||
% writeln(add:_Pos:Env:Pos1:End),
|
% writeln(add:_Pos:Env:Pos1:End),
|
||||||
% listing(stack),
|
% listing(stack),
|
||||||
run( New, End).
|
run( New, End).
|
||||||
|
list( Env, _Line, NewLine, _Pos) :-
|
||||||
|
( Env = "@enumerate" ->
|
||||||
|
NewLine = "<ol>"
|
||||||
|
;
|
||||||
|
NewLine = "<ul>"
|
||||||
|
).
|
||||||
|
|
||||||
item_type("@bullet", _, "-" ).
|
item_type("@bullet", _, "-" ).
|
||||||
item_type("@code", _, "-" ).
|
item_type("@code", _, "-" ).
|
||||||
@ -521,7 +561,9 @@ from_word( Line, Id ) :-
|
|||||||
simplify( C1, C0, []),
|
simplify( C1, C0, []),
|
||||||
string_codes( Id, C1 ).
|
string_codes( Id, C1 ).
|
||||||
|
|
||||||
simplify( [0'_|L]) --> " ", !,
|
simplify( [0'_|L]) --> " ", !, %'
|
||||||
|
simplify(L).
|
||||||
|
simplify( [0's,0'T|L]) --> "*", !, %'
|
||||||
simplify(L).
|
simplify(L).
|
||||||
simplify( [0'a,0'A|L]) --> "@", !,
|
simplify( [0'a,0'A|L]) --> "@", !,
|
||||||
simplify(L).
|
simplify(L).
|
||||||
@ -637,7 +679,7 @@ pop(Type, Val) :-
|
|||||||
stack(T, V), !,
|
stack(T, V), !,
|
||||||
T = Type,
|
T = Type,
|
||||||
V = Val,
|
V = Val,
|
||||||
retract(stack(T,V)).
|
once( retract(stack(T,V)) ).
|
||||||
|
|
||||||
push(Type, Val) :-
|
push(Type, Val) :-
|
||||||
asserta(stack(Type,Val)).
|
asserta(stack(Type,Val)).
|
||||||
@ -706,11 +748,17 @@ run( L) --> "@value{", !,
|
|||||||
run(R).
|
run(R).
|
||||||
run( L) --> "@pxref{", !,
|
run( L) --> "@pxref{", !,
|
||||||
argument(AL, 0'{, 0'}),
|
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(R).
|
||||||
run( L) --> "@ref{", !,
|
run( L) --> "@ref{", !,
|
||||||
argument(AL, 0'{, 0'}),
|
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(R).
|
||||||
run( L) --> "@strong{", !,
|
run( L) --> "@strong{", !,
|
||||||
argument(AL, 0'{, 0'}),
|
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]).
|
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], !.
|
argument0([], 0, _, C ) --> [C], !.
|
||||||
%:- start_low_level_trace.
|
|
||||||
argument0([C|L], I0, C0, C ) --> [C], !,
|
argument0([C|L], I0, C0, C ) --> [C], !,
|
||||||
{ I0 > 0, I is I0-1 },
|
{ I0 > 0, I is I0-1 },
|
||||||
argument0( L, I, C0, C).
|
argument0( L, I, C0, C).
|
||||||
%:- stop_low_level_trace.
|
|
||||||
argument0([C0|L], I0, C0, C ) --> [C0], !,
|
argument0([C0|L], I0, C0, C ) --> [C0], !,
|
||||||
{ I is I0+1 },
|
{ I is I0+1 },
|
||||||
argument0( L, I, C0, C).
|
argument0( L, I, C0, C).
|
||||||
@ -854,11 +900,18 @@ id(X) :-
|
|||||||
X1 is X+100,
|
X1 is X+100,
|
||||||
assert(i(X1)).
|
assert(i(X1)).
|
||||||
|
|
||||||
title(1, page).
|
title(TexTitle, Level, DoxTitle) :-
|
||||||
title(2, section).
|
title( Level, TexTitle),
|
||||||
title(3, subsection).
|
% Level1 is Level + 1,
|
||||||
title(4, subsubsection).
|
title( Level, DoxTitle ), !.
|
||||||
title(5, paragraph).
|
|
||||||
title(6, paragraph).
|
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.
|
%:- spy title_from_words.
|
||||||
|
|
502
docs/yap.tex
502
docs/yap.tex
File diff suppressed because it is too large
Load Diff
@ -55,6 +55,7 @@ A Char N "char"
|
|||||||
A Charsio N "charsio"
|
A Charsio N "charsio"
|
||||||
A Character N "character"
|
A Character N "character"
|
||||||
A CharacterCode N "character_code"
|
A CharacterCode N "character_code"
|
||||||
|
A Charset N "charset"
|
||||||
A CleanCall F "$clean_call"
|
A CleanCall F "$clean_call"
|
||||||
A Colomn N ":"
|
A Colomn N ":"
|
||||||
A CodeSpace N "code_space"
|
A CodeSpace N "code_space"
|
||||||
@ -86,6 +87,7 @@ A Dec10 N "dec10"
|
|||||||
A Default N "default"
|
A Default N "default"
|
||||||
A DevNull N "/dev/null"
|
A DevNull N "/dev/null"
|
||||||
A Diff N "\\="
|
A Diff N "\\="
|
||||||
|
A Discontiguous N "discontiguous"
|
||||||
A Dollar F "$"
|
A Dollar F "$"
|
||||||
A DoLogUpdClause F "$do_log_upd_clause"
|
A DoLogUpdClause F "$do_log_upd_clause"
|
||||||
A DoLogUpdClause0 F "$do_log_upd_clause0"
|
A DoLogUpdClause0 F "$do_log_upd_clause0"
|
||||||
@ -188,6 +190,7 @@ A Minus N "-"
|
|||||||
A Modify N "modify"
|
A Modify N "modify"
|
||||||
A Most N "most"
|
A Most N "most"
|
||||||
A MultiFile F "$mf"
|
A MultiFile F "$mf"
|
||||||
|
A Multiple F "multiple"
|
||||||
A Mutable N "mutable"
|
A Mutable N "mutable"
|
||||||
A MutableVariable F "$mutable_variable"
|
A MutableVariable F "$mutable_variable"
|
||||||
A MyddasDB F "$myddas_db"
|
A MyddasDB F "$myddas_db"
|
||||||
@ -200,6 +203,7 @@ A Nan N "nan"
|
|||||||
A Nb N "nb"
|
A Nb N "nb"
|
||||||
A NbTerm N "nb_term"
|
A NbTerm N "nb_term"
|
||||||
A New N "new"
|
A New N "new"
|
||||||
|
A NoEffect N "no_effect"
|
||||||
A NoMemory N "no_memory"
|
A NoMemory N "no_memory"
|
||||||
A None N "none"
|
A None N "none"
|
||||||
A NonEmptyList N "non_empty_list"
|
A NonEmptyList N "non_empty_list"
|
||||||
@ -287,6 +291,7 @@ A SigUsr1 N "sig_usr1"
|
|||||||
A SigUsr2 N "sig_usr2"
|
A SigUsr2 N "sig_usr2"
|
||||||
A SigVTAlarm N "sig_vtalarm"
|
A SigVTAlarm N "sig_vtalarm"
|
||||||
A SigWakeUp N "sig_wake_up"
|
A SigWakeUp N "sig_wake_up"
|
||||||
|
A Singleton N "singleton"
|
||||||
A Slash N "/"
|
A Slash N "/"
|
||||||
A Socket N "socket"
|
A Socket N "socket"
|
||||||
A SourceSink N "source_sink"
|
A SourceSink N "source_sink"
|
||||||
@ -340,6 +345,7 @@ A UserIn N "user_input"
|
|||||||
A UserOut N "user_output"
|
A UserOut N "user_output"
|
||||||
A VBar N "|"
|
A VBar N "|"
|
||||||
A Var F "$VAR"
|
A Var F "$VAR"
|
||||||
|
A VarBranches N "var_branches"
|
||||||
A HiddenVar F "$V"
|
A HiddenVar F "$V"
|
||||||
A Variable N "variable"
|
A Variable N "variable"
|
||||||
A VersionNumber F "$version_name"
|
A VersionNumber F "$version_name"
|
||||||
|
142
os/pl-read.c
142
os/pl-read.c
@ -126,6 +126,21 @@ reportReadError(ReadData rd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* static int */
|
||||||
|
/* reportSingletons(ReadData rd, singletons, Atom amod, Atom aname, UInt arity) */
|
||||||
|
/* { */
|
||||||
|
/* printMessage(ATOM_warning, PL_FUNCTOR_CHARS, */
|
||||||
|
/* "singletons", 2, */
|
||||||
|
/* PL_TERM, singletons, */
|
||||||
|
/* PL_TERM, mod, */
|
||||||
|
/* PL_FUNCTOR_divide2, */
|
||||||
|
/* PL_ATOM, name, */
|
||||||
|
/* PL_INT, arity); */
|
||||||
|
|
||||||
|
/* return FALSE; */
|
||||||
|
/* } */
|
||||||
|
|
||||||
|
|
||||||
/********************************
|
/********************************
|
||||||
* RAW READING *
|
* RAW READING *
|
||||||
*********************************/
|
*********************************/
|
||||||
@ -953,7 +968,6 @@ callCommentHook(term_t comments, term_t tpos, term_t term)
|
|||||||
|
|
||||||
PL_close_query(qid);
|
PL_close_query(qid);
|
||||||
}
|
}
|
||||||
|
|
||||||
PL_discard_foreign_frame(fid);
|
PL_discard_foreign_frame(fid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1075,6 +1089,126 @@ unify_read_term_position(term_t tpos ARG_LD)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** read_clause(+Stream:stream, -Clause:clause, +Options:list)
|
||||||
|
|
||||||
|
Options:
|
||||||
|
* variable_names(-Names)
|
||||||
|
* process_comment(+Boolean)
|
||||||
|
* comments(-List)
|
||||||
|
* syntax_errors(+Atom)
|
||||||
|
* term_position(-Position)
|
||||||
|
* subterm_positions(-Layout)
|
||||||
|
*/
|
||||||
|
|
||||||
|
static const opt_spec read_clause_options[] =
|
||||||
|
{ { ATOM_variable_names, OPT_TERM },
|
||||||
|
{ ATOM_term_position, OPT_TERM },
|
||||||
|
{ ATOM_subterm_positions, OPT_TERM },
|
||||||
|
{ ATOM_process_comment, OPT_BOOL },
|
||||||
|
{ ATOM_comments, OPT_TERM },
|
||||||
|
{ ATOM_syntax_errors, OPT_ATOM },
|
||||||
|
{ NULL_ATOM, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
read_clause(IOSTREAM *s, term_t term, term_t options ARG_LD)
|
||||||
|
{ read_data rd;
|
||||||
|
int rval;
|
||||||
|
fid_t fid;
|
||||||
|
term_t tpos = 0;
|
||||||
|
term_t comments = 0;
|
||||||
|
term_t opt_comments = 0;
|
||||||
|
int process_comment;
|
||||||
|
atom_t syntax_errors = ATOM_dec10;
|
||||||
|
|
||||||
|
{
|
||||||
|
OPCODE ophook = PredCommentHook->OpcodeOfPred;
|
||||||
|
if (ophook == UNDEF_OPCODE || ophook == FAIL_OPCODE)
|
||||||
|
process_comment = FALSE;
|
||||||
|
else
|
||||||
|
process_comment = TRUE;
|
||||||
|
}
|
||||||
|
if ( !(fid=PL_open_foreign_frame()) )
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
retry:
|
||||||
|
init_read_data(&rd, s PASS_LD);
|
||||||
|
|
||||||
|
if ( options &&
|
||||||
|
!scan_options(options, 0, ATOM_read_option, read_clause_options,
|
||||||
|
&rd.varnames,
|
||||||
|
&tpos,
|
||||||
|
&rd.subtpos,
|
||||||
|
&process_comment,
|
||||||
|
&opt_comments,
|
||||||
|
&syntax_errors) )
|
||||||
|
{ PL_close_foreign_frame(fid);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( opt_comments )
|
||||||
|
{ comments = PL_new_term_ref();
|
||||||
|
} else if ( process_comment )
|
||||||
|
{ if ( !tpos )
|
||||||
|
tpos = PL_new_term_ref();
|
||||||
|
comments = PL_new_term_ref();
|
||||||
|
}
|
||||||
|
|
||||||
|
REGS_FROM_LD
|
||||||
|
rd.module = Yap_GetModuleEntry( LOCAL_SourceModule );
|
||||||
|
if ( comments )
|
||||||
|
rd.comments = PL_copy_term_ref(comments);
|
||||||
|
rd.on_error = syntax_errors;
|
||||||
|
rd.singles = rd.styleCheck & SINGLETON_CHECK ? 1 : 0;
|
||||||
|
if ( (rval=read_term(term, &rd PASS_LD)) &&
|
||||||
|
(!tpos || (rval=unify_read_term_position(tpos PASS_LD))) )
|
||||||
|
{
|
||||||
|
if (rd.singles) {
|
||||||
|
// warning, singletons([X=_A],f(X,Y,Z), pos).
|
||||||
|
printMessage(ATOM_warning,
|
||||||
|
PL_FUNCTOR_CHARS, "singletons", 3,
|
||||||
|
PL_TERM, rd.singles,
|
||||||
|
PL_TERM, term,
|
||||||
|
PL_TERM, tpos );
|
||||||
|
}
|
||||||
|
if ( rd.comments &&
|
||||||
|
(rval = PL_unify_nil(rd.comments)) )
|
||||||
|
{ if ( opt_comments )
|
||||||
|
rval = PL_unify(opt_comments, comments);
|
||||||
|
else if ( !PL_get_nil(comments) )
|
||||||
|
callCommentHook(comments, tpos, term);
|
||||||
|
} else
|
||||||
|
{ if ( rd.has_exception && reportReadError(&rd) )
|
||||||
|
{ PL_rewind_foreign_frame(fid);
|
||||||
|
free_read_data(&rd);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free_read_data(&rd);
|
||||||
|
|
||||||
|
return rval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static
|
||||||
|
PRED_IMPL("read_clause", 3, read_clause, 0)
|
||||||
|
{ PRED_LD
|
||||||
|
int rc;
|
||||||
|
IOSTREAM *s;
|
||||||
|
|
||||||
|
if ( !getTextInputStream(A1, &s) )
|
||||||
|
return FALSE;
|
||||||
|
rc = read_clause(s, A2, A3 PASS_LD);
|
||||||
|
if ( Sferror(s) )
|
||||||
|
return streamStatus(s);
|
||||||
|
else
|
||||||
|
PL_release_stream(s);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
word
|
word
|
||||||
pl_raw_read(term_t term)
|
pl_raw_read(term_t term)
|
||||||
@ -1174,8 +1308,9 @@ retry:
|
|||||||
{ if ( !setDoubleQuotes(dq, &rd.flags) )
|
{ if ( !setDoubleQuotes(dq, &rd.flags) )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if ( rd.singles && PL_get_atom(rd.singles, &w) && w == ATOM_warning )
|
if ( rd.singles && PL_get_atom(rd.singles, &w) && w == ATOM_warning)
|
||||||
rd.singles = TRUE;
|
rd.singles = 1;
|
||||||
|
|
||||||
if ( comments )
|
if ( comments )
|
||||||
rd.comments = PL_copy_term_ref(comments);
|
rd.comments = PL_copy_term_ref(comments);
|
||||||
|
|
||||||
@ -1355,6 +1490,7 @@ PL_chars_to_term(const char *s, term_t t)
|
|||||||
BeginPredDefs(read)
|
BeginPredDefs(read)
|
||||||
PRED_DEF("read_term", 3, read_term, PL_FA_ISO)
|
PRED_DEF("read_term", 3, read_term, PL_FA_ISO)
|
||||||
PRED_DEF("read_term", 2, read_term, PL_FA_ISO)
|
PRED_DEF("read_term", 2, read_term, PL_FA_ISO)
|
||||||
|
PRED_DEF("read_clause", 3, read_clause, 0)
|
||||||
PRED_DEF("atom_to_term", 3, atom_to_term, 0)
|
PRED_DEF("atom_to_term", 3, atom_to_term, 0)
|
||||||
PRED_DEF("term_to_atom", 2, term_to_atom, 0)
|
PRED_DEF("term_to_atom", 2, term_to_atom, 0)
|
||||||
#ifdef O_QUASIQUOTATIONS
|
#ifdef O_QUASIQUOTATIONS
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit d5c70de04a6fce6be71a9086d0164dd0b0c9d9d4
|
Subproject commit 0f77a1e1b90b36bddb1844712380f4f3858123b7
|
@ -1 +1 @@
|
|||||||
Subproject commit abd65ae6486993e04dfa883163efdad3bab789ab
|
Subproject commit a8a43aa09892c4b7018dc053d8e7653e2f648107
|
238
pl/absf.yap
238
pl/absf.yap
@ -4,18 +4,27 @@
|
|||||||
* *
|
* *
|
||||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||||
* *
|
* *
|
||||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-2014 *
|
||||||
* *
|
|
||||||
**************************************************************************
|
|
||||||
* *
|
|
||||||
* File: consult.yap *
|
|
||||||
* Last rev: 8/2/88 *
|
|
||||||
* mods: *
|
|
||||||
* comments: Consulting Files in YAP *
|
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
:- 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,
|
absolute_file_name/3,
|
||||||
add_to_path/1,
|
add_to_path/1,
|
||||||
add_to_path/2,
|
add_to_path/2,
|
||||||
@ -30,20 +39,89 @@
|
|||||||
:- use_system_module( '$_lists', [member/2]).
|
:- use_system_module( '$_lists', [member/2]).
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
absolute_file_name(+File:atom, +Options:list, +Path:atom) is nondet
|
||||||
* @defgroup AbsoluteFileName File Name Resolution
|
absolute_file_name(-File:atom, +Path:atom, +Options:list) is nondet
|
||||||
*
|
|
||||||
* @subsection sub:AbsFileName File Name Resolution in Prolog
|
|
||||||
|
|
||||||
Support for file name resolution through absolute_file_name/3 and
|
_Options_ is a list of options to guide the conversion:
|
||||||
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.
|
|
||||||
|
|
||||||
*/
|
- 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.
|
Converts the given file specification into an absolute path, using default options. See absolute_file_name/3 for details on the options.
|
||||||
*/
|
*/
|
||||||
@ -58,78 +136,6 @@ absolute_file_name(File0,File) :-
|
|||||||
'$absolute_file_name'(F0,[access(read),file_type(source),file_errors(fail),solutions(first),expand(true)],F,G).
|
'$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), !,
|
'$absolute_file_name'(File, _Opts, _TrueFileName, G) :- var(File), !,
|
||||||
'$do_error'(instantiation_error, G).
|
'$do_error'(instantiation_error, G).
|
||||||
@ -455,7 +461,8 @@ absolute_file_name(File,Opts,TrueFileName) :-
|
|||||||
'$add_file_to_dir'(P0,A,Atoms,NFile) :-
|
'$add_file_to_dir'(P0,A,Atoms,NFile) :-
|
||||||
atom_concat([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
|
YAP specific procedure that returns a list of user-defined directories
|
||||||
in the library search-path.
|
in the library search-path.
|
||||||
@ -467,11 +474,18 @@ path(Path) :- findall(X,'$in_path'(X),Path).
|
|||||||
( S = "" -> X = '.' ;
|
( S = "" -> X = '.' ;
|
||||||
atom_codes(X,S) ).
|
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(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) :-
|
add_to_path(New,Pos) :-
|
||||||
atom(New), !,
|
atom(New), !,
|
||||||
'$check_path'(New,Str),
|
'$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,last) :- !, recordz('$path',New,_).
|
||||||
'$add_to_path'(New,first) :- recorda('$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),
|
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'([Ch],[Ch,A]) :- !, integer(Ch), '$dir_separator'(A).
|
||||||
'$check_path'([N|S],[N|SN]) :- integer(N), '$check_path'(S,SN).
|
'$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.
|
:- 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.
|
:- 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) :-
|
user:prolog_file_type(A, executable) :-
|
||||||
current_prolog_flag(shared_object_extension, A).
|
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) :-
|
'$preprocess_args_for_non_commutative'(X, Y, Z, W, E) :-
|
||||||
'$do_and'(Z = X, Y = 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)).
|
||||||
|
|
||||||
|
|
12
pl/boot.yap
12
pl/boot.yap
@ -1187,17 +1187,7 @@ bootstrap(F) :-
|
|||||||
!.
|
!.
|
||||||
|
|
||||||
'$enter_command'(Stream,Mod,Status) :-
|
'$enter_command'(Stream,Mod,Status) :-
|
||||||
read_term(Stream, Command, [module(Mod), variable_names(Vars), term_position(Pos), syntax_errors(dec10), process_comment(true), singletons( Singletons ) ]),
|
read_clause(Stream, Command, [variable_names(Vars), term_position(Pos), syntax_errors(dec10) ]),
|
||||||
( Singletons == []
|
|
||||||
->
|
|
||||||
true
|
|
||||||
;
|
|
||||||
get_value('$syntaxchecksinglevar',on)
|
|
||||||
->
|
|
||||||
'$sv_warning'(Singletons, Command )
|
|
||||||
;
|
|
||||||
true
|
|
||||||
),
|
|
||||||
'$command'(Command,Vars,Pos,Status).
|
'$command'(Command,Vars,Pos,Status).
|
||||||
|
|
||||||
'$abort_loop'(Stream) :-
|
'$abort_loop'(Stream) :-
|
||||||
|
123
pl/checker.yap
123
pl/checker.yap
@ -62,7 +62,7 @@
|
|||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
:- system_module( '$_checker', [no_style_check/1,
|
:- system_module( style_checker, [no_style_check/1,
|
||||||
style_check/1], ['$check_term'/5,
|
style_check/1], ['$check_term'/5,
|
||||||
'$init_style_check'/1,
|
'$init_style_check'/1,
|
||||||
'$sv_warning'/2,
|
'$sv_warning'/2,
|
||||||
@ -76,40 +76,84 @@
|
|||||||
:- op(1150, fx, multifile).
|
:- op(1150, fx, multifile).
|
||||||
|
|
||||||
style_check(V) :- var(V), !, fail.
|
style_check(V) :- var(V), !, fail.
|
||||||
style_check(all) :-
|
style_check(V) :-
|
||||||
'$syntax_check_single_var'(_,on),
|
style_check_(V), !.
|
||||||
'$syntax_check_discontiguous'(_,on),
|
style_check(V) :-
|
||||||
'$syntax_check_multiple'(_,on).
|
\+atom(V), \+ list(V), V \= + _, V \= + _, !,
|
||||||
style_check(single_var) :-
|
'$do_error'( type_error('+|-|?(Flag)', V), style_check(V) ).
|
||||||
'$syntax_check_single_var'(_,on).
|
style_check(V) :-
|
||||||
style_check(singleton) :-
|
\+atom(V), \+ list(V), V \= + _, V \= + _, !,
|
||||||
style_check(single_var).
|
'$do_error'( domain_error(style_name(Flag), V), style_check(V) ).
|
||||||
style_check(-single_var) :-
|
|
||||||
no_style_check(single_var).
|
|
||||||
style_check(-singleton) :-
|
style_check_(all) :-
|
||||||
no_style_check(single_var).
|
'$style_checker'( [ singleton, discontiguous, multiple ] ).
|
||||||
style_check(discontiguous) :-
|
style_check_(single_var) :-
|
||||||
'$syntax_check_discontiguous'(_,on).
|
'$style_checker'( [ singleton ] ).
|
||||||
style_check(-discontiguous) :-
|
style_check_(singleton) :-
|
||||||
no_style_check(discontiguous).
|
'$style_checker'( [ singleton ] ).
|
||||||
style_check(multiple) :-
|
style_check_(+single_var) :-
|
||||||
'$syntax_check_multiple'(_,on).
|
'$style_checker'( [ singleton ] ).
|
||||||
style_check(-multiple) :-
|
style_check_(+singleton) :-
|
||||||
no_style_check(multiple).
|
'$style_checker'( [ singleton ] ).
|
||||||
style_check([]).
|
style_check_(-single_var) :-
|
||||||
style_check([H|T]) :- style_check(H), style_check(T).
|
'$style_checker'( [ -singleton ] ).
|
||||||
|
style_check_(-singleton) :-
|
||||||
|
'$style_checker'( [ -singleton ] ).
|
||||||
|
style_check_(discontiguous) :-
|
||||||
|
'$style_checker'( [ discontiguous ] ).
|
||||||
|
style_check_(+discontiguous) :-
|
||||||
|
'$style_checker'( [ discontiguous ] ).
|
||||||
|
style_check_(-discontiguous) :-
|
||||||
|
'$style_checker'( [ -discontiguous ] ).
|
||||||
|
style_check_(multiple) :-
|
||||||
|
'$style_checker'( [ multiple ] ).
|
||||||
|
style_check_(+multiple) :-
|
||||||
|
'$style_checker'( [ multiple ] ).
|
||||||
|
style_check_(-multiple) :-
|
||||||
|
'$style_checker'( [ -multiple ] ).
|
||||||
|
style_check_(no_effect) :-
|
||||||
|
'$style_checker'( [ no_effect ] ).
|
||||||
|
style_check_(+no_effect) :-
|
||||||
|
'$style_checker'( [ no_effect ] ).
|
||||||
|
style_check_(-no_effect) :-
|
||||||
|
'$style_checker'( [ -no_effect ] ).
|
||||||
|
style_check_(var_branches) :-
|
||||||
|
'$style_checker'( [ var_branches ] ).
|
||||||
|
style_check_(+var_branches) :-
|
||||||
|
'$style_checker'( [ var_branches ] ).
|
||||||
|
style_check_(-var_branches) :-
|
||||||
|
'$style_checker'( [ -var_branches ] ).
|
||||||
|
style_check_(atom) :-
|
||||||
|
'$style_checker'( [ atom ] ).
|
||||||
|
style_check_(+atom) :-
|
||||||
|
'$style_checker'( [ atom ] ).
|
||||||
|
style_check_(-atom) :-
|
||||||
|
'$style_checker'( [ -atom ] ).
|
||||||
|
style_check_(charset) :-
|
||||||
|
'$style_checker'( [ charset ] ).
|
||||||
|
style_check_(+charset) :-
|
||||||
|
'$style_checker'( [ charset ] ).
|
||||||
|
style_check_(-charset) :-
|
||||||
|
'$style_checker'( [ -charset ] ).
|
||||||
|
style_check_('?'(Info) ) :-
|
||||||
|
'$style_checker '( [ L ] ),
|
||||||
|
lists:member( Style, [ singleton, discontiguous, multiple ] ),
|
||||||
|
( lists:member(Style, L ) -> Info = +Style ; Info = -Style ).
|
||||||
|
style_check_([]).
|
||||||
|
style_check_([H|T]) :- style_check(H), style_check(T).
|
||||||
|
|
||||||
no_style_check(V) :- var(V), !, fail.
|
no_style_check(V) :- var(V), !, fail.
|
||||||
no_style_check(all) :-
|
no_style_check(all) :-
|
||||||
'$syntax_check_single_var'(_,off),
|
'$style_checker'( [ -singleton, -discontiguous, -multiple ] ).
|
||||||
'$syntax_check_discontiguous'(_,off),
|
no_style_check(-single_var) :-
|
||||||
'$syntax_check_multiple'(_,off).
|
'$style_checker'( [ -singleton ] ).
|
||||||
no_style_check(single_var) :-
|
no_style_check(-singleton) :-
|
||||||
'$syntax_check_single_var'(_,off).
|
'$style_checker'( [ -singleton ] ).
|
||||||
no_style_check(discontiguous) :-
|
no_style_check(-discontiguous) :-
|
||||||
'$syntax_check_discontiguous'(_,off).
|
'$stylechecker'( [ -discontiguous ] ).
|
||||||
no_style_check(multiple) :-
|
no_style_check(-multiple) :-
|
||||||
'$syntax_check_multiple'(_,off).
|
'$style_checker'( [ -multiple ] ).
|
||||||
no_style_check([]).
|
no_style_check([]).
|
||||||
no_style_check([H|T]) :- no_style_check(H), no_style_check(T).
|
no_style_check([H|T]) :- no_style_check(H), no_style_check(T).
|
||||||
|
|
||||||
@ -183,21 +227,6 @@ no_style_check([H|T]) :- no_style_check(H), no_style_check(T).
|
|||||||
fail.
|
fail.
|
||||||
'$check_term'(_,_,_,_,_).
|
'$check_term'(_,_,_,_,_).
|
||||||
|
|
||||||
'$sv_warning'([], _) :- !.
|
|
||||||
'$sv_warning'(SVs, T) :-
|
|
||||||
strip_module(T, M, T1),
|
|
||||||
'$pred_arity'( T1, Name, Arity ),
|
|
||||||
print_message(warning,singletons(SVs,(M:Name/Arity))).
|
|
||||||
|
|
||||||
'$pred_arity'(V,M,M,V,call,1) :- var(V), !.
|
|
||||||
'$pred_arity'((H:-_),Name,Arity) :- !,
|
|
||||||
functor(H,Name,Arity).
|
|
||||||
'$pred_arity'((H-->_),Name,Arity) :- !,
|
|
||||||
functor(HL,Name,1),
|
|
||||||
Arity is A1+2.
|
|
||||||
'$pred_arity'(H,Name,Arity) :-
|
|
||||||
functor(H,Name,Arity).
|
|
||||||
|
|
||||||
% check if a predicate is discontiguous.
|
% check if a predicate is discontiguous.
|
||||||
'$handle_discontiguous'(F,A,M) :-
|
'$handle_discontiguous'(F,A,M) :-
|
||||||
recorded('$discontiguous_defs','$df'(F,A,M),_), !,
|
recorded('$discontiguous_defs','$df'(F,A,M),_), !,
|
||||||
|
@ -114,6 +114,7 @@ otherwise.
|
|||||||
'ground.yap',
|
'ground.yap',
|
||||||
'listing.yap',
|
'listing.yap',
|
||||||
'preds.yap',
|
'preds.yap',
|
||||||
|
'arithpreds.yap',
|
||||||
% modules must be after preds, otherwise we will have trouble
|
% modules must be after preds, otherwise we will have trouble
|
||||||
% with meta-predicate expansion being invoked
|
% with meta-predicate expansion being invoked
|
||||||
'modules.yap',
|
'modules.yap',
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
[system_message/4,
|
[system_message/4,
|
||||||
prefix/6,
|
prefix/6,
|
||||||
prefix/5,
|
prefix/5,
|
||||||
file_location/3,
|
file_location/3]).
|
||||||
message/3]).
|
|
||||||
|
|
||||||
:- use_system_module( user, [generate_message_hook/3]).
|
:- use_system_module( user, [generate_message_hook/3]).
|
||||||
|
|
||||||
:- multifile message/3.
|
:- multifile prolog:message/3.
|
||||||
|
|
||||||
:- multifile user:generate_message_hook/3.
|
:- multifile user:generate_message_hook/3.
|
||||||
|
|
||||||
@ -156,11 +155,13 @@ system_message(no_match(P)) -->
|
|||||||
[ 'No matching predicate for ~w.' - [P] ].
|
[ 'No matching predicate for ~w.' - [P] ].
|
||||||
system_message(leash([A|B])) -->
|
system_message(leash([A|B])) -->
|
||||||
[ 'Leashing set to ~w.' - [[A|B]] ].
|
[ 'Leashing set to ~w.' - [[A|B]] ].
|
||||||
system_message(singletons([SV=_],P)) -->
|
system_message(singletons(SVs,P,W)) -->
|
||||||
[ 'Singleton variable ~s in ~q.' - [SV,P] ].
|
[ 'Singleton variable~*c ~s in ~q, starting at line ~d' - [NVs, 0's, SVsL, I, L] ], % '
|
||||||
system_message(singletons(SVs,P)) -->
|
{ svs(SVs,SVsL,[]),
|
||||||
[ 'Singleton variables ~s in ~q.' - [SVsL, P] ],
|
( SVs = [_] -> NVs = 0 ; NVs = 1 ),
|
||||||
{ svs(SVs,SVsL,[]) }.
|
clause_to_indicator(P, I),
|
||||||
|
stream_position_data( line_count, W, L)
|
||||||
|
}.
|
||||||
system_message(trace_command(-1)) -->
|
system_message(trace_command(-1)) -->
|
||||||
[ 'EOF is not a valid debugger command.' ].
|
[ 'EOF is not a valid debugger command.' ].
|
||||||
system_message(trace_command(C)) -->
|
system_message(trace_command(C)) -->
|
||||||
@ -582,3 +583,16 @@ prefix(debug(_), '% ', user_error).
|
|||||||
prefix(information, '% ', user_error).
|
prefix(information, '% ', user_error).
|
||||||
|
|
||||||
|
|
||||||
|
clause_to_indicator(T, M:Name/Arity) :-
|
||||||
|
strip_module(T, M, T1),
|
||||||
|
pred_arity( T1, Name, Arity ).
|
||||||
|
|
||||||
|
pred_arity(V,M,M,V,call,1) :- var(V), !.
|
||||||
|
pred_arity((H:-_),Name,Arity) :- !,
|
||||||
|
functor(H,Name,Arity).
|
||||||
|
pred_arity((H-->_),Name,Arity) :- !,
|
||||||
|
functor(HL,Name,1),
|
||||||
|
Arity is A1+2.
|
||||||
|
pred_arity(H,Name,Arity) :-
|
||||||
|
functor(H,Name,Arity).
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user