System Predicates

Various predicates are provided for getting information about the operation of the Prolog engine and the computer environment.

command_line(ArgsL)

command_line/1 succeeds by unifying ArgsL with a list of character code lists, each of which is an argument on the command line used when the program was invoked. The character code lists are a convenient form for doing character-by-character analysis of the argments, or for sending to a DCG parser. They can also be converted to atoms, strings, or terms as necessary.

This predicate can be used only in command-line environments or Windows console mode, but is a useful tool for applications designed to run in those environments. Here is a short sample program illustrating it's use.

Running it (after compiling and linking):

date(MONTH, DAY, YEAR)

date/3 returns the MONTH, DAY and YEAR if unbound. If bound, then it unifies with them. For example, this is the day this bit of documentation was updated:

There is a date-time library that provides predicates for doing date-time arithmetic.

time(HOUR, MIN, SEC)

time/3 succeeds by unifying HOUR, MIN, and SEC to the current time-of-day (hours, minutes, and seconds respectively). HOUR runs from 0 to 24. For example, this is the time this bit of documentation was updated:

There is a date-time library that provides predicates for doing date-time arithmetic.

gc

gc/0 forces garbage collection of unused dynamic clauses, heap cells, and strings. Garbage collection is automatic in Prolog, so in general, it is not necessary to call gc/0.

highwater(Heap, Local, Control, Trail)

highwater/4 predicate returns the approximate highwater marks used by these four control structures. These values, plus some extra space, can then be used in configuration parameters for minimizing the resources required for an application.

loadlsx(FilenameA)

loadlsx dynamically loads a logic server extension at runtime from a Prolog program.

Example:

main :-
 loadlsx('aosutils.lsx'),
 ...

If loadlsx is called from a directive within a module specification, then the predicates for that LSX are loaded in that module.

For example, to hide the xarray sample predicates in a module:

:- module(array_utils).
:- loadlsx('xarray.lsx').
...
:- end_module(array_utils).

pro_heap(Top, Pos)

pro_heap/2 returns the size, Top, and current position, Pos, of the heap.

pro_control(Top, Pos)

pro_control/2 returns the size, Top, and current position, Pos, of the control stack.

pro_local(Top, Pos)

pro_local/2 returns the size, Top, and current position, Pos, of the local stack.

pro_trail(Top, Pos)

pro_trail/2 returns the size, Top, and current position, Pos, of the trail stack.

stack_sizes(Heap, Control, Local, Trail)

stack_sizes returns the number of cells in use on each of the respective stacks.

system(CmdA)

system/1 executes an operating system command or program.

CmdA must be instantiated to an atom representing a command or program that can be executed by the operating system. The call to system/1 succeeds if the command "succeeded". For example:

timer(Ticks)

timer/1 succeeds if Ticks can be instantiated to floating point seconds since some implementation dependent time. The built-in atoms, cputime and cpuclock provide similar functions.

It is intended primarily for timing executions

Note that timings can also be done using the built-in atom, cputime. The value of cputime is the current elapsed time in floating point seconds. It can be used in arithmetic expressions.

version(String)

version/1 returns a string with the current Amzi! version.

Copyright ©1987-2011 Amzi! inc. All Rights Reserved. Amzi! is a registered trademark and Logic Server is a trademark of Amzi! inc.