more doc udates
This commit is contained in:
parent
d5fc0a1920
commit
aeb54ebc61
73
C/mavar.c
73
C/mavar.c
@ -52,6 +52,13 @@ static Int p_get_mutable( USES_REGS1 );
|
||||
static Int p_update_mutable( USES_REGS1 );
|
||||
static Int p_is_mutable( USES_REGS1 );
|
||||
|
||||
/** @pred setarg(+ _I_,+ _S_,? _T_)
|
||||
|
||||
|
||||
Set the value of the _I_th argument of term _S_ to term _T_.
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_setarg( USES_REGS1 )
|
||||
{
|
||||
@ -239,6 +246,13 @@ Yap_UpdateTimedVar(Term inv, Term new)
|
||||
return UpdateTimedVar(inv, new PASS_REGS);
|
||||
}
|
||||
|
||||
/** @pred create_mutable(+ _D_,- _M_)
|
||||
|
||||
|
||||
Create new mutable variable _M_ with initial value _D_.
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_create_mutable( USES_REGS1 )
|
||||
{
|
||||
@ -246,6 +260,13 @@ p_create_mutable( USES_REGS1 )
|
||||
return(Yap_unify(ARG2,t));
|
||||
}
|
||||
|
||||
/** @pred get_mutable(? _D_,+ _M_)
|
||||
|
||||
|
||||
Unify the current value of mutable term _M_ with term _D_.
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_get_mutable( USES_REGS1 )
|
||||
{
|
||||
@ -266,6 +287,14 @@ p_get_mutable( USES_REGS1 )
|
||||
return(Yap_unify(ARG1, t));
|
||||
}
|
||||
|
||||
/** @pred update_mutable(+ _D_,+ _M_)
|
||||
|
||||
|
||||
Set the current value of mutable term _M_ to term _D_.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_update_mutable( USES_REGS1 )
|
||||
{
|
||||
@ -287,6 +316,13 @@ p_update_mutable( USES_REGS1 )
|
||||
}
|
||||
|
||||
static Int
|
||||
/** @pred is_mutable(? _D_)
|
||||
|
||||
|
||||
Holds if _D_ is a mutable term.
|
||||
|
||||
|
||||
*/
|
||||
p_is_mutable( USES_REGS1 )
|
||||
{
|
||||
Term t = Deref(ARG1);
|
||||
@ -308,48 +344,11 @@ void
|
||||
Yap_InitMaVarCPreds(void)
|
||||
{
|
||||
#ifdef MULTI_ASSIGNMENT_VARIABLES
|
||||
/* The most famous contributions of SICStus to the Prolog language */
|
||||
Yap_InitCPred("setarg", 3, p_setarg, SafePredFlag);
|
||||
/** @pred setarg(+ _I_,+ _S_,? _T_)
|
||||
|
||||
|
||||
Set the value of the _I_th argument of term _S_ to term _T_.
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred("create_mutable", 2, p_create_mutable, SafePredFlag);
|
||||
/** @pred create_mutable(+ _D_,- _M_)
|
||||
|
||||
|
||||
Create new mutable variable _M_ with initial value _D_.
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred("get_mutable", 2, p_get_mutable, SafePredFlag);
|
||||
/** @pred get_mutable(? _D_,+ _M_)
|
||||
|
||||
|
||||
Unify the current value of mutable term _M_ with term _D_.
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred("update_mutable", 2, p_update_mutable, SafePredFlag);
|
||||
/** @pred update_mutable(+ _D_,+ _M_)
|
||||
|
||||
|
||||
Set the current value of mutable term _M_ to term _D_.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred("is_mutable", 1, p_is_mutable, SafePredFlag);
|
||||
/** @pred is_mutable(? _D_)
|
||||
|
||||
|
||||
Holds if _D_ is a mutable term.
|
||||
|
||||
|
||||
*/
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1067,3 +1067,6 @@ Yap_Parse(read_data *rd)
|
||||
} else
|
||||
return (0);
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
|
44
C/sysbits.c
44
C/sysbits.c
@ -1952,7 +1952,13 @@ p_true_file_name3 ( USES_REGS1 )
|
||||
}
|
||||
|
||||
/* Executes $SHELL under Prolog */
|
||||
/** @pred sh
|
||||
|
||||
|
||||
Creates a new shell interaction.
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_sh ( USES_REGS1 )
|
||||
{ /* sh */
|
||||
@ -1983,14 +1989,14 @@ p_sh ( USES_REGS1 )
|
||||
#endif
|
||||
}
|
||||
|
||||
static Int
|
||||
p_shell ( USES_REGS1 )
|
||||
{ /* '$shell'(+SystCommand) */
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
/** shell(+Command:text, -Status:integer) is det.
|
||||
|
||||
Run an external command and wait for its completion.
|
||||
*/
|
||||
static Int
|
||||
p_shell ( USES_REGS1 )
|
||||
{ /* '$shell'(+SystCommand) */
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
char *cmd;
|
||||
term_t A1 = Yap_InitSlot(ARG1 PASS_REGS);
|
||||
if ( PL_get_chars(A1, &cmd, CVT_ALL|REP_FN|CVT_EXCEPTION) )
|
||||
@ -2061,14 +2067,15 @@ Run an external command and wait for its completion.
|
||||
#endif /* _MSC_VER */
|
||||
}
|
||||
|
||||
/** system(+Command:text).
|
||||
|
||||
Run an external command.
|
||||
*/
|
||||
|
||||
static Int
|
||||
p_system ( USES_REGS1 )
|
||||
{ /* '$system'(+SystCommand) */
|
||||
#if _MSC_VER || defined(__MINGW32__)
|
||||
/** shell(+Command:text, -Status:integer) is det.
|
||||
|
||||
Run an external command and wait for its completion.
|
||||
*/
|
||||
char *cmd;
|
||||
term_t A1 = Yap_InitSlot(ARG1 PASS_REGS);
|
||||
if ( PL_get_chars(A1, &cmd, CVT_ALL|REP_FN|CVT_EXCEPTION) )
|
||||
@ -2155,6 +2162,13 @@ Run an external command and wait for its completion.
|
||||
|
||||
|
||||
/* Rename a file */
|
||||
/** @pred rename(+ _F_,+ _G_)
|
||||
|
||||
|
||||
Renames file _F_ to _G_.
|
||||
|
||||
|
||||
*/
|
||||
static Int
|
||||
p_mv ( USES_REGS1 )
|
||||
{ /* rename(+OldName,+NewName) */
|
||||
@ -2966,23 +2980,9 @@ Yap_InitSysPreds(void)
|
||||
#endif
|
||||
Yap_InitCPred ("log_event", 1, p_log_event, SafePredFlag|SyncPredFlag);
|
||||
Yap_InitCPred ("sh", 0, p_sh, SafePredFlag|SyncPredFlag);
|
||||
/** @pred sh
|
||||
|
||||
|
||||
Creates a new shell interaction.
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred ("$shell", 1, p_shell, SafePredFlag|SyncPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("system", 1, p_system, SafePredFlag|SyncPredFlag|UserCPredFlag);
|
||||
Yap_InitCPred ("rename", 2, p_mv, SafePredFlag|SyncPredFlag);
|
||||
/** @pred rename(+ _F_,+ _G_)
|
||||
|
||||
|
||||
Renames file _F_ to _G_.
|
||||
|
||||
|
||||
*/
|
||||
Yap_InitCPred ("$yap_home", 1, p_yap_home, SafePredFlag);
|
||||
Yap_InitCPred ("$yap_paths", 3, p_yap_paths, SafePredFlag);
|
||||
Yap_InitCPred ("$dir_separator", 1, p_dir_sp, SafePredFlag);
|
||||
|
@ -1267,7 +1267,7 @@ then
|
||||
AC_CHECK_FUNCS( rl_completion_matches rl_clear_pending_input rl_reset_after_signal )
|
||||
AC_CHECK_FUNCS( rl_filename_completion_function rl_free_line_state rl_insert_close )
|
||||
AC_CHECK_FUNCS( rl_set_prompt rl_free_line_state rl_insert_close add_history )
|
||||
AC_CHECK_FUNCS( rl_begin_undo_group rl_discard_argument )
|
||||
AC_CHECK_FUNCS( rl_begin_undo_group rl_discard_argument rl_set_keyboard_input_timeout )
|
||||
AC_CHECK_DECLS( [ rl_event_hook, rl_catch_signals , rl_readline_state, rl_done ], [], [], [
|
||||
[#include <stdio.h>]
|
||||
[#include <readline/readline.h>]
|
||||
|
26
docs/yap.md
26
docs/yap.md
@ -767,9 +767,9 @@ will be used:
|
||||
+ a preceding minus sign will denote an "output argument";
|
||||
+ an argument with no preceding symbol can be used in both ways.
|
||||
|
||||
@defgroup YAPBuiltins The YAP Core Built-Ins
|
||||
@defgroup YAPBuiltins YAP Built-Ins
|
||||
|
||||
@page Core Core Prolog Built-Ins
|
||||
@page Core Prolog Built-Ins
|
||||
|
||||
+ @ref YAPControl
|
||||
|
||||
@ -779,7 +779,7 @@ will be used:
|
||||
|
||||
+ @ref YAP_Terms
|
||||
|
||||
+ @ref YAP_InputOutput
|
||||
+ @ref InputOutput
|
||||
|
||||
+ @ref YAPOS
|
||||
|
||||
@ -795,6 +795,8 @@ will be used:
|
||||
|
||||
+ @ref Predicates_on_Atoms
|
||||
|
||||
+ @ref Flags
|
||||
|
||||
+ @ref Deb_Preds
|
||||
|
||||
@defgroup ChYInterface Foreign Language interface to YAP
|
||||
@ -892,6 +894,8 @@ being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
+ @ref Block_Diagram Block Diagram
|
||||
|
||||
+ @ref Lambda
|
||||
|
||||
+ @ref Invoking_Predicates_on_all_Members_of_a_List Invoking Predicates on all Members of a List
|
||||
|
||||
@defgroup YAPProgramming Programming in YAP
|
||||
@ -940,10 +944,8 @@ being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
+ @ref shlib
|
||||
|
||||
+ @ref url
|
||||
|
||||
+ @ref Lambda
|
||||
|
||||
+ @ref SWIclib
|
||||
|
||||
+ @ref archive
|
||||
|
||||
+ @ref CHR
|
||||
@ -954,6 +956,7 @@ being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
+ @ref zlib
|
||||
|
||||
|
||||
@defgroup YAPPackages The YAP packages
|
||||
|
||||
@page Packages The YAP Packages
|
||||
@ -974,10 +977,17 @@ being designed to work with the swig (@url(www.swig.org}) interface compiler.
|
||||
|
||||
+ @ref YAP-LBFGS
|
||||
|
||||
@defgroup SWIclib The SWI Extended Operating System Support Package
|
||||
@ingroup SWILibrary
|
||||
|
||||
The HTTP package is a series of libraries developed by Jan Wielmaker
|
||||
and the SWI-Prolog community for extended Operating System support.
|
||||
Please consult clib.doc for the complete documentation.
|
||||
|
||||
@defgroup http The SWI http packages
|
||||
@ingroup SWILibrary
|
||||
|
||||
Tthe package HTTP is a series of libraries developed by Jan Wielmaker
|
||||
The HTTP package is a series of libraries developed by Jan Wielmaker
|
||||
and the SWI-Prolog community for accessing and serving data on the
|
||||
web. It supports lower-level transport protocols, but also
|
||||
data-representation primitives, and more.
|
||||
|
37
os/pl-file.c
37
os/pl-file.c
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
|
||||
/** @addtogroup YAP_inputOutput
|
||||
/** @addtogroup InputOutput
|
||||
@{
|
||||
|
||||
*/
|
||||
@ -120,14 +120,13 @@ standardStreamIndexFromStream(IOSTREAM *s)
|
||||
return -1;
|
||||
}
|
||||
|
||||
//! @}
|
||||
/*******************************
|
||||
* BOOKKEEPING *
|
||||
*******************************/
|
||||
|
||||
/**
|
||||
* @defgroup YAP_StreamM Stream Manipulation
|
||||
* @ingroup YAP_InputOutput
|
||||
* @defgroup StreamM Stream Manipulation
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
*/
|
||||
static void aliasStream(IOSTREAM *s, atom_t alias);
|
||||
@ -2665,10 +2664,10 @@ PRED_IMPL("read_pending_input", 3, read_pending_input, 0)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// @}
|
||||
//! @}
|
||||
|
||||
//! @defgroup YAPCharsIO Character Input/Output
|
||||
// @ingroup YAP_InputOutput
|
||||
//! @defgroup CharsIO Character Input/Output
|
||||
// @ingroup InputOutput
|
||||
// @{
|
||||
//
|
||||
|
||||
@ -3735,9 +3734,11 @@ PRED_IMPL("open", 3, open3, PL_FA_ISO)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
/** @defgroup DEC10_IO DEC-10/C-Prolog Compatible File Handling
|
||||
*
|
||||
* @ingroup YAP_InputOutput
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
*/
|
||||
/*******************************
|
||||
@ -3995,8 +3996,8 @@ PRED_IMPL("told", 0, told, 0)
|
||||
* @}
|
||||
*/
|
||||
|
||||
//! @defgroup YAPStream Opening and Closing Streams
|
||||
// @ingroup YAP_InputOutput
|
||||
//! @defgroup Stream Opening and Closing Streams
|
||||
// @ingroup InputOutput
|
||||
// @{
|
||||
//
|
||||
|
||||
@ -4869,7 +4870,7 @@ PRED_IMPL("is_stream", 1, is_stream, 0)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup YAPStreamM
|
||||
* @addtogroup StreamM
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -4918,7 +4919,7 @@ PRED_IMPL("flush_output", 1, flush_output1, PL_FA_ISO)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup YAPStream
|
||||
* @addtogroup Stream
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -5342,7 +5343,7 @@ peek(term_t stream, term_t chr, int how ARG_LD)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup YAPCharsIO
|
||||
* @addtogroup CharsIO
|
||||
* @{
|
||||
*/
|
||||
|
||||
@ -5442,6 +5443,15 @@ PRED_IMPL("peek_char", 1, peek_char1, 0)
|
||||
return peek(0, A1, PL_CHAR PASS_LD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup StreamM
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/*******************************
|
||||
* INTERACTION *
|
||||
@ -6028,3 +6038,4 @@ init_yap(void)
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup YAP_Format Formatted Output
|
||||
* @ingroup YAP_InputOutput
|
||||
* @defgroup Format Formatted Output
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
@ -21,13 +21,12 @@
|
||||
*/
|
||||
|
||||
/** @defgroup SetLocale Localization Support
|
||||
* @ingroup YAP_InputOutput
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
*
|
||||
* This code includes support for localization, that is, the ability to support
|
||||
* different languages and representation formats.
|
||||
*
|
||||
* The code was written by Jan Wielemaker for SWI-Prolog.
|
||||
*/
|
||||
#include "pl-incl.h"
|
||||
#include "pl-locale.h"
|
||||
|
@ -21,6 +21,9 @@
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
//! @addtogroup Flags
|
||||
//@{
|
||||
|
||||
/*#define O_DEBUG 1*/
|
||||
#include "pl-incl.h"
|
||||
#ifdef __YAP_PROLOG__
|
||||
@ -1323,3 +1326,6 @@ BeginPredDefs(prologflag)
|
||||
PRED_DEF("$swi_set_prolog_flag", 2, set_prolog_flag, PL_FA_ISO)
|
||||
PRED_DEF("$swi_create_prolog_flag", 3, create_prolog_flag, 0)
|
||||
EndPredDefs
|
||||
|
||||
//! @}
|
||||
|
||||
|
74
os/pl-read.c
74
os/pl-read.c
@ -7,7 +7,11 @@
|
||||
|
||||
#include "pl-read.h" /* read structure */
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup ReadTerm Read Term from Streams
|
||||
* @ingroup InputOutput
|
||||
* @{
|
||||
*/
|
||||
|
||||
static bool
|
||||
isStringStream(IOSTREAM *s)
|
||||
@ -1089,17 +1093,6 @@ 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 },
|
||||
@ -1111,6 +1104,18 @@ static const opt_spec read_clause_options[] =
|
||||
};
|
||||
|
||||
|
||||
/** read_clause(+Stream:stream, -Clause:clause, +Options:list)
|
||||
|
||||
Like read_term/3, but uses current compiler options.
|
||||
|
||||
Options:
|
||||
* variable_names(-Names)
|
||||
* process_comment(+Boolean)
|
||||
* comments(-List)
|
||||
* syntax_errors(+Atom)
|
||||
* term_position(-Position)
|
||||
* subterm_positions(-Layout)
|
||||
*/
|
||||
static int
|
||||
read_clause(IOSTREAM *s, term_t term, term_t options ARG_LD)
|
||||
{
|
||||
@ -1240,7 +1245,7 @@ static const opt_spec read_term_options[] =
|
||||
{ ATOM_variables, OPT_TERM },
|
||||
{ ATOM_singletons, OPT_TERM },
|
||||
{ ATOM_term_position, OPT_TERM },
|
||||
{ ATOM_subterm_positions, OPT_TERM },
|
||||
// { ATOM_subterm_positions, OPT_TERM },
|
||||
{ ATOM_character_escapes, OPT_BOOL },
|
||||
{ ATOM_double_quotes, OPT_ATOM },
|
||||
{ ATOM_module, OPT_ATOM },
|
||||
@ -1364,18 +1369,15 @@ return rval;
|
||||
}
|
||||
|
||||
|
||||
/** read_term(+Stream, -Term, +Options) is det.
|
||||
*/
|
||||
/** @pred read_term(+ _Stream_,- _T_,+ _Options_) is iso
|
||||
|
||||
static
|
||||
PRED_IMPL("read_term", 3, read_term, PL_FA_ISO)
|
||||
/** @pred read_term(+ _S_,- _T_,+ _Options_) is iso
|
||||
|
||||
Reads term _T_ from stream _S_ with execution controlled by the
|
||||
Reads term _T_ from stream _Stream_ with execution controlled by the
|
||||
same options as read_term/2.
|
||||
|
||||
|
||||
*/
|
||||
static
|
||||
PRED_IMPL("read_term", 3, read_term, PL_FA_ISO)
|
||||
{ PRED_LD
|
||||
IOSTREAM *s;
|
||||
|
||||
@ -1395,23 +1397,34 @@ return FALSE;
|
||||
*/
|
||||
|
||||
|
||||
static
|
||||
PRED_IMPL("read_term", 2, read_term, PL_FA_ISO)
|
||||
/** @pred read_term(- _T_,+ _Options_) is iso
|
||||
|
||||
|
||||
Reads term _T_ from the current input stream with execution
|
||||
controlled by the following options:
|
||||
|
||||
+ comments(- _Comments_)
|
||||
|
||||
Unify _Comments_ with a list of string terms including comments before
|
||||
and within the term.
|
||||
|
||||
+ module( + _Module_)
|
||||
|
||||
Read term using _Module_ as source module.
|
||||
|
||||
+ quasi_quotations(-List)
|
||||
|
||||
Unify _List_ with the quasi-quotations present in the term.
|
||||
|
||||
+ term_position(- _Position_)
|
||||
|
||||
Unify _Position_ with a term describing the position of the stream
|
||||
Unify _Position_ with a term describing the position of the stream
|
||||
at the start of parse. Use stream_position_data/3 to obtain extra
|
||||
information.
|
||||
|
||||
+ singletons(- _Names_)
|
||||
|
||||
Unify _Names_ with a list of the form _Name=Var_, where
|
||||
Unify _Names_ with a list of the form _Name=Var_, where
|
||||
_Name_ is the name of a non-anonymous singleton variable in the
|
||||
original term, and `Var` is the variable's representation in
|
||||
YAP.
|
||||
@ -1419,18 +1432,20 @@ The variables occur in left-to-right traversal order.
|
||||
|
||||
+ syntax_errors(+ _Val_)
|
||||
|
||||
Control action to be taken after syntax errors. See yap_flag/2
|
||||
Control action to be taken after syntax errors. See yap_flag/2
|
||||
for detailed information.
|
||||
|
||||
+ variables(- _Names_)
|
||||
|
||||
Unify _Names_ with a list of the form _Name=Var_, where _Name_ is
|
||||
Unify _Names_ with a list of the form _Name=Var_, where _Name_ is
|
||||
the name of a non-anonymous variable in the original term, and _Var_
|
||||
is the variable's representation in YAP.
|
||||
The variables occur in left-to-right traversal order.
|
||||
|
||||
|
||||
*/
|
||||
static
|
||||
PRED_IMPL("read_term", 2, read_term, PL_FA_ISO)
|
||||
{ PRED_LD
|
||||
IOSTREAM *s;
|
||||
|
||||
@ -1537,8 +1552,6 @@ LD->read_source = oldsrc;
|
||||
return Yap_GetFromSlot( tt PASS_REGS);
|
||||
}
|
||||
|
||||
static
|
||||
PRED_IMPL("atom_to_term", 3, atom_to_term, 0)
|
||||
/** @pred atom_to_term(+ _Atom_, - _Term_, - _Bindings_)
|
||||
|
||||
|
||||
@ -1546,6 +1559,8 @@ Use _Atom_ as input to read_term/2 using the option `variable_names` and return
|
||||
|
||||
|
||||
*/
|
||||
static
|
||||
PRED_IMPL("atom_to_term", 3, atom_to_term, 0)
|
||||
{ return atom_to_term(A1, A2, A3);
|
||||
}
|
||||
|
||||
@ -1589,3 +1604,6 @@ PRED_DEF("term_to_atom", 2, term_to_atom, 0)
|
||||
PRED_DEF("$qq_open", 2, qq_open, 0)
|
||||
#endif
|
||||
EndPredDefs
|
||||
|
||||
//! @}
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
/** @defgroup YAPWrite Outputting a term to a Stream
|
||||
* @ingroup YAP_InputOutput
|
||||
/** @defgroup Write Outputting a term to a Stream
|
||||
* @ingroup InputOutput
|
||||
*
|
||||
* @brief Predicates that output a term to a stream. The predicates
|
||||
* call upon write_term/3 to do the actual work. They differ on the
|
||||
|
@ -36,7 +36,7 @@ PFL is included with the YAP Prolog system. The commands to perform a default i
|
||||
2 `$ git clone git://yap.git.sourceforge.net/gitroot/yap/yap-6.3`
|
||||
3 `$ cd yap-6.3/`
|
||||
4 `$ ./configure --enable-clpbn-bp --prefix=$HOME`
|
||||
5 `$ make depend \& make install`
|
||||
5 `$ make depend & make install`
|
||||
|
||||
In case you want to install YAP somewhere else or with different settings, please consult the YAP documentation. From now on, we will assume that the directory `$HOME/bin` (where the binary is) is in your `$PATH` environment variable.
|
||||
|
||||
@ -54,7 +54,7 @@ Where,
|
||||
|
||||
+ _F_ is a comma-separated sequence of Prolog terms that will define sets of random variables under the constraint _C_. If _Type_ is `bayes`, the first term defines the node while the remaining terms define its parents.
|
||||
|
||||
+ _Phi_ is either a Prolog list of potential values or a Prolog goal that unifies with one. Notice that if _Type_ is `bayes`, this will correspond to the conditional probability table. Domain combinations are implicitly assumed in ascending order, with the first term being the 'most significant' (e.g. _\mathtt{x_0y_0}_, _\mathtt{x_0y_1}_, _\mathtt{x_0y_2}_, _\mathtt{x_1y_0}_, _\mathtt{x_1y_1}_, _\mathtt{x_1y_2}_).
|
||||
+ _Phi_ is either a Prolog list of potential values or a Prolog goal that unifies with one. Notice that if _Type_ is `bayes`, this will correspond to the conditional probability table. Domain combinations are implicitly assumed in ascending order, with the first term being the 'most significant' (e.g. _x_0y_0_, _x_0y_1_, _x_0y_2_, _x_1y_0_, _x_1y_1_, _x_1y_2_).
|
||||
|
||||
+ _C_ is a (possibly empty) list of Prolog goals that will instantiate the logical variables that appear in _F_, that is, the successful substitutions for the goals in _C_ will be the valid values for the logical variables. This allows the constraint to be defined as any relation (set of tuples) over the logical variables.
|
||||
|
||||
@ -116,7 +116,7 @@ markov friends(X,Y), smokes(X), smokes(Y) ;
|
||||
%markov friends(X,Y) ; [1.0, 99.484] ; [person(X), person(Y)].
|
||||
~~~~
|
||||
|
||||
Notice that we have defined the world to be consisted of only two persons, `anna` and `bob`. We can easily add as many persons as we want by inserting in the program a fact like `person @ 10.`~. This would automatically create ten persons named `p1`, `p2`, \dots, `p10`.
|
||||
Notice that we have defined the world to be consisted of only two persons, `anna` and `bob`. We can easily add as many persons as we want by inserting in the program a fact like `person @ 10.`~. This would automatically create ten persons named `p1`, `p2`, dots, `p10`.
|
||||
|
||||
Unlike other fist-order probabilistic languages, in PFL the logical variables that appear in the terms are not directly typed, and they will be only constrained by the goals that appears in the constraint of the parfactor. This allows the logical variables to be constrained to any relation (set of tuples), and not only pairwise (in)equalities. For instance, the next example defines a network with three ground factors, each defined respectively over the random variables `p(a,b)`, `p(b,d)` and `p(d,e)`.
|
||||
|
||||
@ -149,13 +149,13 @@ Assuming that the current directory is the one where the examples are located, f
|
||||
|
||||
Let's suppose that we want to estimate the marginal probability for the $WetGrass$ random variable. To do so, we call the following goal.
|
||||
|
||||
`?- wet\_grass(X).`
|
||||
`?- wet_grass(X).`
|
||||
|
||||
The output of this goal will show the marginal probability for each $WetGrass$ possible state or value, that is, `t` and `f`. Notice that in PFL a random variable is identified by a term with the same functor and arguments plus one extra argument.
|
||||
|
||||
Now let's suppose that we want to estimate the probability for the same random variable, but this time we have evidence that it had rained in the day before. We can estimate this probability without resorting to static evidence with:
|
||||
|
||||
`?- wet\_grass(X), rain(t).`
|
||||
`?- wet_grass(X), rain(t).`
|
||||
|
||||
PFL also supports calculating joint probability distributions. For instance, we can obtain the joint probability for $Sprinkler$ and $Rain$ with:
|
||||
|
||||
@ -168,7 +168,7 @@ PFL also supports calculating joint probability distributions. For instance, we
|
||||
%------------------------------------------------------------------------------
|
||||
%------------------------------------------------------------------------------
|
||||
### Options
|
||||
PFL supports both ground and lifted inference methods. The inference algorithm can be chosen by calling `set\_solver/1`. The following are supported:
|
||||
PFL supports both ground and lifted inference methods. The inference algorithm can be chosen by calling `set_solver/1`. The following are supported:
|
||||
+ `ve`, variable elimination (written in Prolog)
|
||||
+ `hve`, variable elimination (written in C++)
|
||||
+ `jt`, junction tree
|
||||
@ -182,81 +182,81 @@ PFL supports both ground and lifted inference methods. The inference algorithm c
|
||||
|
||||
For instance, if we want to use belief propagation to solve some probabilistic query, we need to call first:
|
||||
|
||||
`?- set\_solver(bp).`
|
||||
`?- set_solver(bp).`
|
||||
|
||||
It is possible to tweak some parameters of PFL through `set\_pfl\_flag/2` predicate. The first argument is a option name that identifies the parameter that we want to tweak. The second argument is some possible value for this option. Next we explain the available options in detail.
|
||||
It is possible to tweak some parameters of PFL through `set_pfl_flag/2` predicate. The first argument is a option name that identifies the parameter that we want to tweak. The second argument is some possible value for this option. Next we explain the available options in detail.
|
||||
|
||||
\optionsection{verbosity}
|
||||
+ verbosity
|
||||
This option controls the level of debugging information that will be shown.
|
||||
|
||||
+ Values: a positive integer (default is 0 - no debugging). The higher the number, the more information that will be shown.
|
||||
+ Affects: `hve`, `bp`, `cbp`, `lve`, `lkc` and `lbp`.
|
||||
+ Values: a positive integer (default is 0 - no debugging). The higher the number, the more information that will be shown.
|
||||
+ Affects: `hve`, `bp`, `cbp`, `lve`, `lkc` and `lbp`.
|
||||
|
||||
For instance, we can view some basic debugging information by calling the following goal.
|
||||
|
||||
`?- set\_pfl\_flag(verbosity, 1).`
|
||||
`?- set_pfl_flag(verbosity, 1).`
|
||||
|
||||
|
||||
\optionsection{use\_logarithms}
|
||||
+ use_logarithms
|
||||
This option controls whether the calculations performed during inference should be done in a logarithm domain or not.
|
||||
+ Values: `true` (default) or `false`.
|
||||
+ Affects: `hve`, `bp`, `cbp`, `lve`, `lkc` and `lbp`.
|
||||
+ Values: `true` (default) or `false`.
|
||||
+ Affects: `hve`, `bp`, `cbp`, `lve`, `lkc` and `lbp`.
|
||||
|
||||
|
||||
\optionsection{hve\_elim\_heuristic}
|
||||
+ hve_elim_heuristic
|
||||
This option allows to choose which elimination heuristic will be used by the `hve`.
|
||||
+ Values: `sequential`, `min\_neighbors`, `min\_weight`, `min\_fill` and\\ `weighted\_min\_fill` (default).
|
||||
+ Affects: `hve`.
|
||||
+ Values: `sequential`, `min_neighbors`, `min_weight`, `min_fill` and `weighted_min_fill` (default).
|
||||
+ Affects: `hve`.
|
||||
|
||||
An explanation for each of these heuristics can be found in Daphne Koller's book \textit{Probabilistic Graphical Models}.
|
||||
An explanation for each of these heuristics can be found in Daphne Koller's book textit{Probabilistic Graphical Models}.
|
||||
|
||||
|
||||
\optionsection{bp\_max\_iter}
|
||||
+ bp_max_iter
|
||||
This option establishes a maximum number of iterations. One iteration consists in sending all possible messages.
|
||||
|
||||
+ Values: a positive integer (default is `1000`).
|
||||
+ Affects: `bp`, `cbp` and `lbp`.
|
||||
+ Values: a positive integer (default is `1000`).
|
||||
+ Affects: `bp`, `cbp` and `lbp`.
|
||||
|
||||
|
||||
\optionsection{bp\_accuracy}
|
||||
+ bp_accuracy
|
||||
This option allows to control when the message passing should cease. Be the residual of one message the difference (according some metric) between the one sent in the current iteration and the one sent in the previous. If the highest residual is lesser than the given value, the message passing is stopped and the probabilities are calculated using the last messages that were sent.
|
||||
|
||||
+ Values: a float-point number (default is `0.0001`).
|
||||
+ Affects: `bp`, `cbp` and `lbp`.
|
||||
+ Values: a float-point number (default is `0.0001`).
|
||||
+ Affects: `bp`, `cbp` and `lbp`.
|
||||
|
||||
|
||||
+ bp\_msg\_schedule
|
||||
+ bp_msg_schedule
|
||||
This option allows to control the message sending order.
|
||||
+ Values:
|
||||
+ `seq\_fixed` (default), at each iteration, all messages are sent with the same order.
|
||||
+ Values:
|
||||
+ `seq_fixed` (default), at each iteration, all messages are sent with the same order.
|
||||
|
||||
+ `seq\_random`, at each iteration, all messages are sent with a random order.
|
||||
+ `seq_random`, at each iteration, all messages are sent with a random order.
|
||||
|
||||
+ `parallel`, at each iteration, all messages are calculated using only the values of the previous iteration.
|
||||
+ `parallel`, at each iteration, all messages are calculated using only the values of the previous iteration.
|
||||
|
||||
+ `max\_residual`, the next message to be sent is the one with maximum residual (as explained in the paper \textit{Residual Belief Propagation: Informed Scheduling for Asynchronous Message Passing}).
|
||||
+ `max_residual`, the next message to be sent is the one with maximum residual (as explained in the paper textit{Residual Belief Propagation: Informed Scheduling for Asynchronous Message Passing}).
|
||||
|
||||
+ Affects: `bp`, `cbp` and `lbp`.
|
||||
|
||||
|
||||
+ export\_libdai
|
||||
+ export_libdai
|
||||
This option allows exporting the current model to the libDAI, http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html, file format.
|
||||
+ Values: `true` or `false` (default).
|
||||
+ Affects: `hve`, `bp`, and `cbp`.
|
||||
|
||||
|
||||
+ export\_uai
|
||||
This option allows exporting the current model to the \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08} file format.
|
||||
+ export_uai
|
||||
This option allows exporting the current model to the href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08} file format.
|
||||
+ Values: `true` or `false` (default).
|
||||
+ Affects: `hve`, `bp`, and `cbp`.
|
||||
|
||||
|
||||
+ export\_graphviz
|
||||
This option allows exporting the factor graph's structure into a format that can be parsed by \href{http://www.graphviz.org/}{Graphviz}.
|
||||
+ export_graphviz
|
||||
This option allows exporting the factor graph's structure into a format that can be parsed by href{http://www.graphviz.org/}{Graphviz}.
|
||||
+ Values: `true` or `false` (default).
|
||||
+ Affects: `hve`, `bp`, and `cbp`.
|
||||
|
||||
+ print\_fg
|
||||
+ print_fg
|
||||
This option allows to print a textual representation of the factor graph.
|
||||
+ Values: `true` or `false` (default).
|
||||
+ Affects: `hve`, `bp`, and `cbp`.
|
||||
@ -295,9 +295,7 @@ scan_data([cloudy(C), sprinkler(S), rain(R), wet_grass(W)]) :-
|
||||
|
||||
Parameter learning is done by calling the `em/5` predicate. Its arguments are the following.
|
||||
|
||||
\begin{center}
|
||||
`em(+Data, +MaxError, +MaxIters, -CPTs, -LogLik)`
|
||||
\end{center}
|
||||
|
||||
Where,
|
||||
+ `Data` is a list of samples for the distribution that we want to estimate. Each sample is a list of either observed random variables or unobserved random variables (denoted when its state or value is not instantiated).
|
||||
@ -307,14 +305,14 @@ Where,
|
||||
+ `LogLik` is the log-likelihood.
|
||||
|
||||
|
||||
It is possible to choose the solver that will be used for the inference part during parameter learning with the `set\_em\_solver/1` predicate (defaults to `hve`). At the moment, only the following solvers support parameter learning: `ve`, `hve`, `bdd`, `bp` and `cbp`.
|
||||
It is possible to choose the solver that will be used for the inference part during parameter learning with the `set_em_solver/1` predicate (defaults to `hve`). At the moment, only the following solvers support parameter learning: `ve`, `hve`, `bdd`, `bp` and `cbp`.
|
||||
|
||||
Inside the `learning` directory from the examples directory, one can find more examples of parameter learning.
|
||||
|
||||
|
||||
|
||||
### External Interface
|
||||
This package also includes an external command for perform inference over probabilistic graphical models described in formats other than PFL. Currently two are support, the \href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI file format}, and the \href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08 file format}.
|
||||
This package also includes an external command for perform inference over probabilistic graphical models described in formats other than PFL. Currently two are support, the href{http://cs.ru.nl/~jorism/libDAI/doc/fileformats.html}{libDAI file format}, and the href{http://graphmod.ics.uci.edu/uai08/FileFormat}{UAI08 file format}.
|
||||
|
||||
This command's name is `hcli` and its usage is as follows.
|
||||
|
||||
@ -343,7 +341,7 @@ By default, all probability tasks are resolved using the `hve` solver. It is pos
|
||||
|
||||
Notice that only the `hve`, `bp` and `cbp` solvers can be used with `hcli`.
|
||||
|
||||
The options that are available with the `set\_pfl\_flag/2` predicate can be used in `hcli` too. The syntax is a pair `<Option>=<Value>` before the model's file name.
|
||||
The options that are available with the `set_pfl_flag/2` predicate can be used in `hcli` too. The syntax is a pair `<Option>=<Value>` before the model's file name.
|
||||
|
||||
*/
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9caa663c7694094bafee1c055052ef8c771b5193
|
||||
Subproject commit 3d7af0e671a3ce88b20df8b8e110d312df3749fe
|
15
pl/absf.yap
15
pl/absf.yap
@ -459,6 +459,21 @@ absolute_file_name(File0,File) :-
|
||||
'$add_file_to_dir'(P0,A,Atoms,NFile) :-
|
||||
atom_concat([P0,A,Atoms],NFile).
|
||||
|
||||
/** @pred prolog_file_name( +File, -PrologFileName)
|
||||
|
||||
Unify _PrologFileName_ with the Prolog file associated to _File_.
|
||||
|
||||
*/
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
var(File), !,
|
||||
'$do_error'(instantiation_error, prolog_file_name(File, PrologFileName)).
|
||||
prolog_file_name(user, Out) :- !, Out = user.
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
atom(File), !,
|
||||
operating_system_support:true_file_name(File, PrologFileName).
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
'$do_error'(type_error(atom,T), prolog_file_name(File, PrologFileName)).
|
||||
|
||||
/**
|
||||
@pred path(-Directories:list) is det,deprecated
|
||||
|
||||
|
@ -1509,6 +1509,8 @@ End of conditional compilation.
|
||||
'$access_yap_flags'(11,1), !.
|
||||
'$fetch_comp_status'(compact).
|
||||
|
||||
consult_depth(LV) :- '$show_consult_level'(LV).
|
||||
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
|
@ -407,6 +407,23 @@ setup_call_catcher_cleanup(Setup, Goal, Catcher, Cleanup) :-
|
||||
'$nb_getval'('$catch', Ball, fail),
|
||||
throw(Ball).
|
||||
|
||||
/** @pred call_with_args(+ _Name_,...,? _Ai_,...)
|
||||
|
||||
|
||||
Meta-call where _Name_ is the name of the procedure to be called and
|
||||
the _Ai_ are the arguments. The number of arguments varies between 0
|
||||
and 10. New code should use `call/N` for better portability.
|
||||
|
||||
If _Name_ is a complex term, then call_with_args/n behaves as
|
||||
call/n:
|
||||
|
||||
~~~~~{.prolog}
|
||||
call(p(X1,...,Xm), Y1,...,Yn) :- p(X1,...,Xm,Y1,...,Yn).
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
|
||||
%%% Some "dirty" predicates
|
||||
|
||||
% Only efective if yap compiled with -DDEBUG
|
||||
|
@ -26,6 +26,11 @@
|
||||
yap_flag/2,
|
||||
yap_flag/3], []).
|
||||
|
||||
/** @defgroup Flags YAP Execution Flags
|
||||
@ingroup YAPBuiltins
|
||||
@{
|
||||
*/
|
||||
|
||||
:- use_system_module( '$_boot', ['$prompt_alternatives_on'/1]).
|
||||
|
||||
:- use_system_module( '$_checker', ['$syntax_check_discontiguous'/2,
|
||||
@ -1377,7 +1382,6 @@ The state of source mode can either be on or off. When the source mode
|
||||
is on, all clauses are kept both as compiled code and in a "hidden"
|
||||
database. _O_ is unified with the previous state and the mode is set
|
||||
according to _N_.
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
/** @defgroup LoadForeign Access to Code Written in other Programming Languages
|
||||
/** @defgroup LoadForeign Access to Foreign Language Programs
|
||||
@ingroup YAPBuiltins
|
||||
@{
|
||||
|
||||
*/
|
||||
|
||||
@ -183,3 +184,17 @@ open_shared_object(File, Opts, Handle) :-
|
||||
'$open_shared_opt'(Opt, Goal, _) :-
|
||||
'$do_error'(domain_error(open_shared_object_option,Opt),Goal).
|
||||
|
||||
/** @pred call_shared_object_function(+ _Handle_, + _Function_)
|
||||
|
||||
|
||||
Call the named function in the loaded shared library. The function
|
||||
is called without arguments and the return-value is
|
||||
ignored. In SWI-Prolog, normally this function installs foreign
|
||||
language predicates using calls to `PL_register_foreign()`.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
%%! @}
|
||||
|
||||
|
436
pl/modules.yap
436
pl/modules.yap
@ -1008,443 +1008,7 @@ its parent goal.
|
||||
% comma has its own problems.
|
||||
:- '$install_meta_predicate'(','(0,0), prolog).
|
||||
|
||||
/** @pred all( _T_,+ _G_,- _L_)
|
||||
|
||||
|
||||
Similar to `findall( _T_, _G_, _L_)` but eliminate
|
||||
repeated elements. Thus, assuming the same clauses as in the above
|
||||
example, the reply to the query
|
||||
|
||||
~~~~~
|
||||
all(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = _33
|
||||
L = [2,1];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
Note that all/3 will fail if no answers are found.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred bagof( _T_,+ _G_,- _L_) is iso
|
||||
|
||||
|
||||
For each set of possible instances of the free variables occurring in
|
||||
_G_ but not in _T_, generates the list _L_ of the instances of
|
||||
_T_ satisfying _G_. Again, assuming the same clauses as in the
|
||||
examples above, the reply to the query
|
||||
|
||||
~~~~~
|
||||
bagof(X,a(X,Y),L).
|
||||
|
||||
would be:
|
||||
X = _32
|
||||
Y = 1
|
||||
L = [2,1];
|
||||
X = _32
|
||||
Y = 2
|
||||
L = [2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
/** @pred bb_delete(+ _Key_,? _Term_)
|
||||
|
||||
|
||||
Delete any term stored in the blackboard under key _Key_ and unify
|
||||
it with _Term_. Fail silently if no such term exists.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred bb_get(+ _Key_,? _Term_)
|
||||
|
||||
|
||||
Unify _Term_ with a term stored in the blackboard under key
|
||||
_Key_, or fail silently if no such term exists.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred bb_put(+ _Key_,? _Term_)
|
||||
|
||||
|
||||
Store term table _Term_ in the blackboard under key _Key_. If a
|
||||
previous term was stored under key _Key_ it is simply forgotten.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred bb_update(+ _Key_,? _Term_,? _New_)
|
||||
|
||||
|
||||
Atomically unify a term stored in the blackboard under key _Key_
|
||||
with _Term_, and if the unification succeeds replace it by
|
||||
_New_. Fail silently if no such term exists or if unification fails.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred call_with_args(+ _Name_,...,? _Ai_,...)
|
||||
|
||||
|
||||
Meta-call where _Name_ is the name of the procedure to be called and
|
||||
the _Ai_ are the arguments. The number of arguments varies between 0
|
||||
and 10. New code should use `call/N` for better portability.
|
||||
|
||||
If _Name_ is a complex term, then call_with_args/n behaves as
|
||||
call/n:
|
||||
|
||||
~~~~~{.prolog}
|
||||
call(p(X1,...,Xm), Y1,...,Yn) :- p(X1,...,Xm,Y1,...,Yn).
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
/** @pred findall( _T_,+ _G_,+ _L_,- _L0_)
|
||||
|
||||
Similar to findall/3, but appends all answers to list _L0_.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred findall( _T_,+ _G_,- _L_) is iso
|
||||
|
||||
|
||||
Unifies _L_ with a list that contains all the instantiations of the
|
||||
term _T_ satisfying the goal _G_.
|
||||
|
||||
With the following program:
|
||||
|
||||
~~~~~
|
||||
a(2,1).
|
||||
a(1,1).
|
||||
a(2,2).
|
||||
~~~~~
|
||||
the answer to the query
|
||||
|
||||
~~~~~
|
||||
findall(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = _33
|
||||
L = [2,1,2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
/** @pred format(+ _S_,+ _T_,+ _L_)
|
||||
|
||||
Print formatted output to stream _S_.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred format(+ _T_,+ _L_)
|
||||
|
||||
|
||||
Print formatted output to the current output stream. The arguments in
|
||||
list _L_ are output according to the string or atom _T_.
|
||||
|
||||
A control sequence is introduced by a `w`. The following control
|
||||
sequences are available in YAP:
|
||||
|
||||
|
||||
|
||||
+ `~~`
|
||||
Print a single tilde.
|
||||
|
||||
+ `~a`
|
||||
The next argument must be an atom, that will be printed as if by `write`.
|
||||
|
||||
+ `~Nc`
|
||||
The next argument must be an integer, that will be printed as a
|
||||
character code. The number _N_ is the number of times to print the
|
||||
character (default 1).
|
||||
|
||||
+ `~Ne`
|
||||
+ `~NE`
|
||||
+ `~Nf`
|
||||
+ `~Ng`
|
||||
+ `~NG`
|
||||
The next argument must be a floating point number. The float _F_, the number
|
||||
_N_ and the control code `c` will be passed to `printf` as:
|
||||
|
||||
~~~~~{.prolog}
|
||||
printf("%s.Nc", F)
|
||||
~~~~~
|
||||
|
||||
As an example:
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("~8e, ~8E, ~8f, ~8g, ~8G~w",
|
||||
[3.14,3.14,3.14,3.14,3.14,3.14]).
|
||||
3.140000e+00, 3.140000E+00, 3.140000, 3.14, 3.143.14
|
||||
~~~~~
|
||||
|
||||
+ `~Nd`
|
||||
The next argument must be an integer, and _N_ is the number of digits
|
||||
after the decimal point. If _N_ is `0` no decimal points will be
|
||||
printed. The default is _N = 0_.
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("~2d, ~d",[15000, 15000]).
|
||||
150.00, 15000
|
||||
~~~~~
|
||||
|
||||
+ `~ND`
|
||||
Identical to `~Nd`, except that commas are used to separate groups
|
||||
of three digits.
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("~2D, ~D",[150000, 150000]).
|
||||
1,500.00, 150,000
|
||||
~~~~~
|
||||
|
||||
+ `~i`
|
||||
Ignore the next argument in the list of arguments:
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format('The ~i met the boregrove',[mimsy]).
|
||||
The met the boregrove
|
||||
~~~~~
|
||||
|
||||
+ `~k`
|
||||
Print the next argument with `write_canonical`:
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("Good night ~k",a+[1,2]).
|
||||
Good night +(a,[1,2])
|
||||
~~~~~
|
||||
|
||||
+ `~Nn`
|
||||
Print _N_ newlines (where _N_ defaults to 1).
|
||||
|
||||
+ `~NN`
|
||||
Print _N_ newlines if at the beginning of the line (where _N_
|
||||
defaults to 1).
|
||||
|
||||
+ `~Nr`
|
||||
The next argument must be an integer, and _N_ is interpreted as a
|
||||
radix, such that `2 <= N <= 36` (the default is 8).
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("~2r, 0x~16r, ~r",
|
||||
[150000, 150000, 150000]).
|
||||
100100100111110000, 0x249f0, 444760
|
||||
~~~~~
|
||||
|
||||
Note that the letters `a-z` denote digits larger than 9.
|
||||
|
||||
+ `~NR`
|
||||
Similar to `~NR`. The next argument must be an integer, and _N_ is
|
||||
interpreted as a radix, such that `2 <= N <= 36` (the default is 8).
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("~2r, 0x~16r, ~r",
|
||||
[150000, 150000, 150000]).
|
||||
100100100111110000, 0x249F0, 444760
|
||||
~~~~~
|
||||
|
||||
The only difference is that letters `A-Z` denote digits larger than 9.
|
||||
|
||||
+ `~p`
|
||||
Print the next argument with print/1:
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("Good night ~p",a+[1,2]).
|
||||
Good night a+[1,2]
|
||||
~~~~~
|
||||
|
||||
+ `~q`
|
||||
Print the next argument with writeq/1:
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("Good night ~q",'Hello'+[1,2]).
|
||||
Good night 'Hello'+[1,2]
|
||||
~~~~~
|
||||
|
||||
+ `~Ns`
|
||||
The next argument must be a list of character codes. The system then
|
||||
outputs their representation as a string, where _N_ is the maximum
|
||||
number of characters for the string ( _N_ defaults to the length of the
|
||||
string).
|
||||
|
||||
~~~~~{.prolog}
|
||||
?- format("The ~s are ~4s",["woods","lovely"]).
|
||||
The woods are love
|
||||
~~~~~
|
||||
|
||||
+ `~w`
|
||||
Print the next argument with write/1:
|
||||
|
||||
~~~~~
|
||||
?- format("Good night ~w",'Hello'+[1,2]).
|
||||
Good night Hello+[1,2]
|
||||
~~~~~
|
||||
|
||||
|
||||
The number of arguments, `N`, may be given as an integer, or it
|
||||
may be given as an extra argument. The next example shows a small
|
||||
procedure to write a variable number of `a` characters:
|
||||
|
||||
~~~~~
|
||||
write_many_as(N) :-
|
||||
format("~*c",[N,0'a]).
|
||||
~~~~~
|
||||
|
||||
The format/2 built-in also allows for formatted output. One can
|
||||
specify column boundaries and fill the intermediate space by a padding
|
||||
character:
|
||||
|
||||
+ `~N|`
|
||||
Set a column boundary at position _N_, where _N_ defaults to the
|
||||
current position.
|
||||
|
||||
+ `~N+`
|
||||
Set a column boundary at _N_ characters past the current position, where
|
||||
_N_ defaults to `8`.
|
||||
|
||||
+ `~Nt`
|
||||
Set padding for a column, where _N_ is the fill code (default is
|
||||
`SPC`).
|
||||
|
||||
|
||||
|
||||
The next example shows how to align columns and padding. We first show
|
||||
left-alignment:
|
||||
|
||||
~~~~~
|
||||
?- format("~n*Hello~16+*~n",[]).
|
||||
*Hello *
|
||||
~~~~~
|
||||
|
||||
Note that we reserve 16 characters for the column.
|
||||
|
||||
The following example shows how to do right-alignment:
|
||||
|
||||
~~~~~
|
||||
?- format("*~tHello~16+*~n",[]).
|
||||
* Hello*
|
||||
|
||||
~~~~~
|
||||
|
||||
The `~t` escape sequence forces filling before `Hello`.
|
||||
|
||||
We next show how to do centering:
|
||||
|
||||
~~~~~
|
||||
?- format("*~tHello~t~16+*~n",[]).
|
||||
* Hello *
|
||||
~~~~~
|
||||
|
||||
The two `~t` escape sequence force filling both before and after
|
||||
`Hello`. Space is then evenly divided between the right and the
|
||||
left sides.
|
||||
|
||||
|
||||
*/
|
||||
/** @pred setof( _X_,+ _P_,- _B_) is iso
|
||||
|
||||
|
||||
Similar to `bagof( _T_, _G_, _L_)` but sorts list
|
||||
_L_ and keeping only one copy of each element. Again, assuming the
|
||||
same clauses as in the examples above, the reply to the query
|
||||
|
||||
~~~~~
|
||||
setof(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = 1
|
||||
L = [1,2];
|
||||
X = _32
|
||||
Y = 2
|
||||
L = [2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred with_output_to(+ _Ouput_,: _Goal_)
|
||||
|
||||
|
||||
Run _Goal_ as once/1, while characters written to the current
|
||||
output are sent to _Output_. The predicate is SWI-Prolog
|
||||
specific.
|
||||
|
||||
Applications should generally avoid creating atoms by breaking and
|
||||
concatenating other atoms as the creation of large numbers of
|
||||
intermediate atoms generally leads to poor performance, even more so in
|
||||
multi-threaded applications. This predicate supports creating
|
||||
difference-lists from character data efficiently. The example below
|
||||
defines the DCG rule `term/3` to insert a term in the output:
|
||||
|
||||
~~~~~
|
||||
term(Term, In, Tail) :-
|
||||
with_output_to(codes(In, Tail), write(Term)).
|
||||
|
||||
?- phrase(term(hello), X).
|
||||
|
||||
X = [104, 101, 108, 108, 111]
|
||||
~~~~~
|
||||
|
||||
+ A Stream handle or alias
|
||||
Temporary switch current output to the given stream. Redirection using with_output_to/2 guarantees the original output is restored, also if Goal fails or raises an exception. See also call_cleanup/2.
|
||||
+ atom(- _Atom_)
|
||||
Create an atom from the emitted characters. Please note the remark above.
|
||||
+ string(- _String_)
|
||||
Create a string-object (not supported in YAP).
|
||||
+ codes(- _Codes_)
|
||||
Create a list of character codes from the emitted characters, similar to atom_codes/2.
|
||||
+ codes(- _Codes_, - _Tail_)
|
||||
Create a list of character codes as a difference-list.
|
||||
+ chars(- _Chars_)
|
||||
Create a list of one-character-atoms codes from the emitted characters, similar to atom_chars/2.
|
||||
+ chars(- _Chars_, - _Tail_)
|
||||
Create a list of one-character-atoms as a difference-list.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred call_shared_object_function(+ _Handle_, + _Function_)
|
||||
|
||||
|
||||
Call the named function in the loaded shared library. The function
|
||||
is called without arguments and the return-value is
|
||||
ignored. In SWI-Prolog, normally this function installs foreign
|
||||
language predicates using calls to `PL_register_foreign()`.
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/** @pred with_mutex(+ _MutexId_, : _Goal_)
|
||||
|
||||
|
||||
Execute _Goal_ while holding _MutexId_. If _Goal_ leaves
|
||||
choicepoints, these are destroyed (as in once/1). The mutex is unlocked
|
||||
regardless of whether _Goal_ succeeds, fails or raises an exception.
|
||||
An exception thrown by _Goal_ is re-thrown after the mutex has been
|
||||
successfully unlocked. See also `mutex_create/2`.
|
||||
|
||||
Although described in the thread-section, this predicate is also
|
||||
available in the single-threaded version, where it behaves simply as
|
||||
once/1.
|
||||
|
||||
|
||||
*/
|
||||
:- meta_predicate
|
||||
abolish(:),
|
||||
abolish(:,+),
|
||||
|
106
pl/setof.yap
106
pl/setof.yap
@ -61,6 +61,36 @@ _^Goal :-
|
||||
% existential quantifier on every variable.
|
||||
|
||||
|
||||
/** @pred findall( _T_,+ _G_,- _L_) is iso
|
||||
|
||||
|
||||
Unifies _L_ with a list that contains all the instantiations of the
|
||||
term _T_ satisfying the goal _G_.
|
||||
|
||||
With the following program:
|
||||
|
||||
~~~~~
|
||||
a(2,1).
|
||||
a(1,1).
|
||||
a(2,2).
|
||||
~~~~~
|
||||
the answer to the query
|
||||
|
||||
~~~~~
|
||||
findall(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = _33
|
||||
L = [2,1,2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
|
||||
findall(Template, Generator, Answers) :-
|
||||
( '$is_list_or_partial_list'(Answers) ->
|
||||
true
|
||||
@ -71,6 +101,12 @@ findall(Template, Generator, Answers) :-
|
||||
|
||||
|
||||
% If some answers have already been found
|
||||
/** @pred findall( _T_,+ _G_,+ _L_,- _L0_)
|
||||
|
||||
Similar to findall/3, but appends all answers to list _L0_.
|
||||
|
||||
|
||||
*/
|
||||
findall(Template, Generator, Answers, SoFar) :-
|
||||
'$findall'(Template, Generator, SoFar, Answers).
|
||||
|
||||
@ -108,7 +144,32 @@ findall(Template, Generator, Answers, SoFar) :-
|
||||
'$collect_with_common_vars'(Answers, VarList).
|
||||
|
||||
% This is the setof predicate
|
||||
/** @pred setof( _X_,+ _P_,- _B_) is iso
|
||||
|
||||
|
||||
Similar to `bagof( _T_, _G_, _L_)` but sorts list
|
||||
_L_ and keeping only one copy of each element. Again, assuming the
|
||||
same clauses as in the examples above, the reply to the query
|
||||
|
||||
~~~~~
|
||||
setof(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = 1
|
||||
L = [1,2];
|
||||
X = _32
|
||||
Y = 2
|
||||
L = [2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
setof(Template, Generator, Set) :-
|
||||
( '$is_list_or_partial_list'(Set) ->
|
||||
true
|
||||
@ -124,6 +185,29 @@ setof(Template, Generator, Set) :-
|
||||
% and we need to find the solutions for each instantiation
|
||||
% of these variables
|
||||
|
||||
/** @pred bagof( _T_,+ _G_,- _L_) is iso
|
||||
|
||||
|
||||
For each set of possible instances of the free variables occurring in
|
||||
_G_ but not in _T_, generates the list _L_ of the instances of
|
||||
_T_ satisfying _G_. Again, assuming the same clauses as in the
|
||||
examples above, the reply to the query
|
||||
|
||||
~~~~~
|
||||
bagof(X,a(X,Y),L).
|
||||
|
||||
would be:
|
||||
X = _32
|
||||
Y = 1
|
||||
L = [2,1];
|
||||
X = _32
|
||||
Y = 2
|
||||
L = [2];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
|
||||
*/
|
||||
bagof(Template, Generator, Bag) :-
|
||||
( '$is_list_or_partial_list'(Bag) ->
|
||||
true
|
||||
@ -171,7 +255,29 @@ bagof(Template, Generator, Bag) :-
|
||||
% as an alternative to setof you can use the predicate all(Term,Goal,Solutions)
|
||||
% But this version of all does not allow for repeated answers
|
||||
% if you want them use findall
|
||||
/** @pred all( _T_,+ _G_,- _L_)
|
||||
|
||||
|
||||
Similar to `findall( _T_, _G_, _L_)` but eliminate
|
||||
repeated elements. Thus, assuming the same clauses as in the above
|
||||
example, the reply to the query
|
||||
|
||||
~~~~~
|
||||
all(X,a(X,Y),L).
|
||||
~~~~~
|
||||
would be:
|
||||
|
||||
~~~~~
|
||||
X = _32
|
||||
Y = _33
|
||||
L = [2,1];
|
||||
no
|
||||
~~~~~
|
||||
|
||||
Note that all/3 will fail if no answers are found.
|
||||
|
||||
|
||||
*/
|
||||
all(T, G same X,S) :- !, all(T same X,G,Sx), '$$produce'(Sx,S,X).
|
||||
all(T,G,S) :-
|
||||
'$init_db_queue'(Ref),
|
||||
|
@ -15,6 +15,8 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
%%! @addtogroup OS
|
||||
%% @{
|
||||
:- system_module( '$_signals', [alarm/3,
|
||||
on_exception/3,
|
||||
on_signal/3,
|
||||
@ -329,3 +331,5 @@ read_sig.
|
||||
:- '$set_no_trace'('$execute_nonstop'(_,_), prolog).
|
||||
:- '$set_no_trace'('$restore_regs'(_,_), prolog).
|
||||
|
||||
%%! @}
|
||||
|
||||
|
@ -14,6 +14,9 @@
|
||||
* comments: sorting in Prolog *
|
||||
* *
|
||||
*************************************************************************/
|
||||
/** @addtogroup Comparing_Terms
|
||||
@{
|
||||
*/
|
||||
:- system_module( '$_sort', [keysort/2,
|
||||
length/2,
|
||||
msort/2,
|
||||
@ -201,3 +204,5 @@ predmerge(=, P, H1, _, T1, T2, [H1|R]) :-
|
||||
predmerge(<, P, H1, H2, T1, T2, [H1|R]) :-
|
||||
predmerge(P, T1, [H2|T2], R).
|
||||
|
||||
%%! @}
|
||||
|
||||
|
@ -1071,6 +1071,21 @@ mutex_unlock_all :-
|
||||
'$unlock_mutex'(Id),
|
||||
'$mutex_unlock_all'(Id).
|
||||
|
||||
/** @pred with_mutex(+ _MutexId_, : _Goal_)
|
||||
|
||||
|
||||
Execute _Goal_ while holding _MutexId_. If _Goal_ leaves
|
||||
choicepoints, these are destroyed (as in once/1). The mutex is unlocked
|
||||
regardless of whether _Goal_ succeeds, fails or raises an exception.
|
||||
An exception thrown by _Goal_ is re-thrown after the mutex has been
|
||||
successfully unlocked. See also `mutex_create/2`.
|
||||
|
||||
Although described in the thread-section, this predicate is also
|
||||
available in the single-threaded version, where it behaves simply as
|
||||
once/1.
|
||||
|
||||
|
||||
*/
|
||||
with_mutex(M, G) :-
|
||||
( '$no_threads' ->
|
||||
once(G)
|
||||
@ -1516,6 +1531,8 @@ thread_peek_message(Queue, Term) :-
|
||||
'$unlock_mutex'(Mutex),
|
||||
fail.
|
||||
|
||||
%% @}
|
||||
|
||||
/** @defgroup Signalling_Threads Signalling Threads
|
||||
@ingroup Threadas
|
||||
|
||||
@ -1667,3 +1684,4 @@ thread_local(X) :-
|
||||
/**
|
||||
@}
|
||||
*/
|
||||
>
|
||||
|
107
pl/yio.yap
107
pl/yio.yap
@ -16,7 +16,7 @@
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
/** @defgroup YAP_InputOutput Input/Output Predicates
|
||||
/** @defgroup InputOutput Input/Output Predicates
|
||||
@ingroup YAPBuiltins
|
||||
@{
|
||||
|
||||
@ -130,8 +130,15 @@ setting and clearing this flag are given under 7.7.
|
||||
'$check_boolean'(X,B,T,G) :-
|
||||
'$do_error'(domain_error(B,T),G).
|
||||
|
||||
/** @pred socket(+ _DOMAIN_,- _SOCKET_)
|
||||
/** @defgroup IO_Sockets YAP Old Style Socket and Pipe Interface
|
||||
@ingroup InputOutput
|
||||
@{
|
||||
|
||||
Autoload the socket/pipe library
|
||||
|
||||
*/
|
||||
|
||||
/** @pred socket(+ _DOMAIN_,- _SOCKET_)
|
||||
|
||||
Call socket/4 with _TYPE_ bound to `SOCK_STREAM'` and
|
||||
_PROTOCOL_ bound to `0`.
|
||||
@ -150,7 +157,6 @@ socket(Domain, Sock) :-
|
||||
|
||||
/** @pred socket(+ _DOMAIN_,+ _TYPE_,+ _PROTOCOL_,- _SOCKET_)
|
||||
|
||||
|
||||
Corresponds to the BSD system call `socket`. Create a socket for
|
||||
domain _DOMAIN_ of type _TYPE_ and protocol
|
||||
_PROTOCOL_. Both _DOMAIN_ and _TYPE_ should be atoms,
|
||||
@ -206,6 +212,11 @@ socket_connect(Sock, Host, Read) :-
|
||||
),
|
||||
yap_sockets:ip_socket(Domain, Type, Protocol, Sock).
|
||||
|
||||
/** @pred open_pipe_streams(Read, Write)
|
||||
|
||||
Autoload old pipe access interface
|
||||
|
||||
*/
|
||||
open_pipe_streams(Read, Write) :-
|
||||
(
|
||||
'$undefined'(pipe(_,_),unix)
|
||||
@ -219,9 +230,11 @@ open_pipe_streams(Read, Write) :-
|
||||
set_stream(Read, encoding(X) ),
|
||||
set_stream(Write, encoding(X) ).
|
||||
|
||||
/** @pred fileerrors
|
||||
%%! @}
|
||||
|
||||
|
||||
/** @pred fileerrors
|
||||
|
||||
Switches on the file_errors flag so that in certain error conditions
|
||||
Input/Output predicates will produce an appropriated message and abort.
|
||||
|
||||
@ -230,7 +243,6 @@ fileerrors :- '$swi_set_prolog_flag'(fileerrors, true).
|
||||
|
||||
/** @pred nofileerrors
|
||||
|
||||
|
||||
Switches off the file_errors flag, so that the predicates see/1,
|
||||
tell/1, open/3 and close/1 just fail, instead of producing
|
||||
an error message and aborting whenever the specified file cannot be
|
||||
@ -241,18 +253,19 @@ nofileerrors :- '$swi_set_prolog_flag'(fileerrors, false).
|
||||
|
||||
/** @pred exists(+ _F_)
|
||||
|
||||
|
||||
Checks if file _F_ exists in the current directory.
|
||||
|
||||
*/
|
||||
exists(F) :-
|
||||
absolute_file_name(F, _, [file_errors(fail),access(exist),expand(true)]).
|
||||
|
||||
%%! @addtogroup ReadTerm
|
||||
% @{
|
||||
|
||||
/* Term IO */
|
||||
|
||||
/** @pred read(- _T_) is iso
|
||||
|
||||
|
||||
Reads the next term from the current input stream, and unifies it with
|
||||
_T_. The term must be followed by a dot (`.`) and any blank-character
|
||||
as previously defined. The syntax of the term must match the current
|
||||
@ -274,6 +287,10 @@ stream.
|
||||
read(Stream,T) :-
|
||||
read_term(Stream, T, []).
|
||||
|
||||
%%! @}
|
||||
|
||||
%%! @addtogroup Write
|
||||
% @{
|
||||
|
||||
/* meaning of flags for '$write' is
|
||||
1 quote illegal atoms
|
||||
@ -305,15 +322,6 @@ Like display/1, but using stream _S_ to display the term.
|
||||
display(Stream, T) :-
|
||||
write_term(Term, T, [ignore_ops(true)]).
|
||||
|
||||
/** @pred format(+ _T_)
|
||||
|
||||
Print formatted output to the current output stream.
|
||||
|
||||
|
||||
*/
|
||||
format(T) :-
|
||||
format(T, []).
|
||||
|
||||
/** @pred writeln( _T_) is iso
|
||||
|
||||
|
||||
@ -332,6 +340,25 @@ writeln(T) :-
|
||||
set_value('$portray',true), fail.
|
||||
'$portray'(_) :- set_value('$portray',false), fail.
|
||||
|
||||
%%! @}
|
||||
|
||||
%%! @addtogroup Format
|
||||
% @{
|
||||
|
||||
/** @pred format(+ _T_)
|
||||
|
||||
Print formatted output to the current output stream.
|
||||
|
||||
|
||||
*/
|
||||
format(T) :-
|
||||
format(T, []).
|
||||
|
||||
%%! @}
|
||||
|
||||
%%! @addtogroup CharsIO
|
||||
% @{
|
||||
|
||||
/* character I/O */
|
||||
|
||||
/** @pred ttyget(- _C_)
|
||||
@ -376,20 +403,26 @@ ttyput(N) :- N1 is N, put(user_output,N1).
|
||||
|
||||
Outputs a new line to stream user_output.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
*/
|
||||
ttynl :- nl(user_output).
|
||||
|
||||
%%! @}
|
||||
|
||||
%%! @addtogroup StreamM
|
||||
% @{
|
||||
|
||||
/** @pred current_line_number(- _LineNumber_)
|
||||
|
||||
Unify _LineNumber_ with the line number for the current output stream.
|
||||
|
||||
*/
|
||||
current_line_number(N) :-
|
||||
current_input(Stream),
|
||||
line_count(Stream, N).
|
||||
|
||||
/** @pred current_line_number(+ _Stream_,- _LineNumber_)
|
||||
|
||||
Unify _LineNumber_ with the line number for the _Stream_.
|
||||
|
||||
Unify _LineNumber_ with the line number for _Stream_.
|
||||
|
||||
*/
|
||||
current_line_number(Stream,N) :-
|
||||
@ -397,32 +430,42 @@ current_line_number(Stream,N) :-
|
||||
|
||||
/** @pred stream_position(+ _Stream_,- _StreamPosition_)
|
||||
|
||||
|
||||
Unify _StreamPosition_ with the packaged information of position on
|
||||
current stream _Stream_. Use stream_position_data/3 to
|
||||
retrieve information on character or line count.
|
||||
|
||||
|
||||
*/
|
||||
stream_position(Stream, Position) :-
|
||||
stream_property(Stream, position(Position)).
|
||||
|
||||
/** @pred stream_position(+ _Stream_,- _StreamPosition_, +_NewPosition_)
|
||||
|
||||
Unify _StreamPosition_ with the packaged information of position on
|
||||
current stream _Stream_ an then moves to position _NewPosition_.
|
||||
|
||||
*/
|
||||
stream_position(Stream, Position, NewPosition) :-
|
||||
stream_property(Stream, position(Position)),
|
||||
set_stream_position(Stream, NewPosition).
|
||||
|
||||
/** @pred at_end_of_line
|
||||
|
||||
Tests whether the next character in the current input stream is a line break character.
|
||||
*/
|
||||
|
||||
at_end_of_line :-
|
||||
current_input(S),
|
||||
at_end_of_line(S).
|
||||
|
||||
/** @pred at_end_of_line( +Stream )
|
||||
|
||||
Tests whether the next character in the stream is a line break character.
|
||||
*/
|
||||
at_end_of_line(S) :-
|
||||
stream_property(S, end_of_stream(past)), !.
|
||||
at_end_of_line(S) :-
|
||||
peek_code(S,N), ( N = 10 -> true ; N = -1).
|
||||
|
||||
|
||||
consult_depth(LV) :- '$show_consult_level'(LV).
|
||||
|
||||
/** @pred current_char_conversion(? _IN_,? _OUT_) is iso
|
||||
|
||||
|
||||
@ -545,15 +588,7 @@ stream_position_data(Prop, Term, Value) :-
|
||||
'$set_default_expand'(V) :- !,
|
||||
'$do_error'(domain_error(flag_value,V),yap_flag(open_expands_file_name,X)).
|
||||
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
var(File), !,
|
||||
'$do_error'(instantiation_error, prolog_file_name(File, PrologFileName)).
|
||||
prolog_file_name(user, Out) :- !, Out = user.
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
atom(File), !,
|
||||
operating_system_support:true_file_name(File, PrologFileName).
|
||||
prolog_file_name(File, PrologFileName) :-
|
||||
'$do_error'(type_error(atom,T), prolog_file_name(File, PrologFileName)).
|
||||
%%! @}
|
||||
|
||||
|
||||
'$codes_to_chars'(String0, String, String0) :- String0 == String, !.
|
||||
|
Reference in New Issue
Block a user