☰

Classic Prolog predicates

Author(s): Daniel Cabeza, Jose F. Morales, Manuel Hermenegildo.

This module reexports the predicates required by the classical Prolog package.

Usage and interface

  • Library usage:
    :- use_module(library(classic/classic_predicates)).

Documentation on exports

PREDICATEop/3
ISOop(Precedence,Type,Name)

Reexported from operators.

PREDICATEcurrent_op/3
ISOcurrent_op(Precedence,Type,Op)

Reexported from operators.

PROPERTYmember/2

Usage:member(X,L)

X is an element of L.

Reexported from basic_props.

PREDICATEappend/3

Reexported from lists.

PREDICATEdelete/3

Usage:delete(L1,E,L2)

L2 is L1 without the occurrences of E.

Reexported from lists.

PREDICATEselect/3

Usage:select(X,Xs,Ys)

Xs and Ys have the same elements except for one occurrence of X.

Reexported from lists.

PREDICATEnth/3
nth(N,List,Elem)

Usage 1:

Unifies Elem and the Nth element of List.

Usage 2:

Finds the positions where Elem is in List. Positions are found in ascending order.

Reexported from lists.

PREDICATElast/2

Usage:last(L,X)

X is the last element of list L.

Reexported from lists.

PREDICATEreverse/2

Usage:reverse(Xs,Ys)

Reverses the order of elements in Xs.

Reexported from lists.

PREDICATElength/2

Usage 1:length(L,N)

Computes the length of L.

Usage 2:length(L,N)

Outputs L of length N.

Usage 3:length(L,N)

Checks that L is of length N.

Usage 4:length(L,N)

Generates Ls and Ns. L can be partially instantiated.

Reexported from lists.

PREDICATEuse_module/1

Reexported from compiler.

PREDICATEuse_module/2

Reexported from compiler.

Reexported from compiler.

PREDICATEsetof/3
ISOsetof(Template,Generator,Set)

Reexported from aggregates.

PREDICATEbagof/3
ISObagof(Template,Generator,Bag)

Reexported from aggregates.

PREDICATEfindall/3
ISOfindall(Template,Generator,List)

Reexported from aggregates.

PREDICATEfindall/4

Usage:

As findall/3, but returning in Tail the tail of List (findall(Template, Generator, List, Tail)).

Reexported from aggregates.

PREDICATEfindnsols/4
findnsols(N,Template,Generator,List)

Reexported from aggregates.

PREDICATEfindnsols/5
findnsols(N,Template,Generator,List,Tail)

Reexported from aggregates.

PREDICATE^/2

Usage:X^P

Existential quantification: X is existentially quantified in P. E.g., in A^p(A,B), A is existentially quantified. Used only within aggregation predicates. In all other contexts, simply, execute the procedure call P.

Reexported from aggregates.

PREDICATEread/1
ISOread(Term)

Reexported from read.

PREDICATEread/2
ISO

Usage:read(Stream,Term)

The next term, delimited by a full-stop (i.e., a . followed by either a space or a control character), is read from Stream and is unified with Term. The syntax of the term must agree with current operator declarations. If the end of Stream has been reached, Term is unified with the term end_of_file. Further calls to read/2 for the same stream will then cause an error, unless the stream is connected to the terminal (in which case a prompt is opened on the terminal).

Reexported from read.

PREDICATEread_term/2
ISO

Usage:read_term(Term,Options)

Like read_term/3, but reading from the current input

Reexported from read.

PREDICATEread_term/3
ISO

Usage:read_term(Stream,Term,Options)

Reads a Term from Stream with the ISO-Prolog Options. These options can control the behavior of read term (see read_option/1).

Reexported from read.

read_top_level(Stream,Data,Variables)

Reexported from read.

Usage:second_prompt(Old,New)

Changes the prompt (the second prompt, as opposed to the first one, used by the toplevel) used by read/2 and friends to New, and returns the current one in Old.

Reexported from read.

Usage:read_option(Option)

Option is an allowed read_term/[2,3] option. These options are:

read_option(variables(_V)).
read_option(variable_names(_N)).
read_option(singletons(_S)).
read_option(lines(_StartLine,_EndLine)).
read_option(dictionary(_Dict)).
They can be used to return the singleton variables in the term, a list of variables, etc.

Reexported from read.

PREDICATEwrite_term/3
ISO

Usage:write_term(Stream,Term,OptList)

Outputs the term Term to the stream Stream, with the list of write-options OptList. See write_option/1 type for default options.

Reexported from write.

PREDICATEwrite_term/2
ISO

Usage:write_term(Term,OptList)

Behaves like current_output(S), write_term(S,Term,OptList).

Reexported from write.

Usage:write_option(Opt)

Opt is a valid write option.

Reexported from write.

PREDICATEwrite/2
ISO

Usage:write(Stream,Term)

Behaves like write_term(Stream, Term, [numbervars(true)]).

Reexported from write.

PREDICATEwrite/1
ISO

Usage:write(Term)

Behaves like current_output(S), write(S,Term).

Reexported from write.

PREDICATEwriteq/2
ISO

Usage:writeq(Stream,Term)

Behaves like write_term(Stream, Term, [quoted(true), numbervars(true)]).

Reexported from write.

PREDICATEwriteq/1
ISO

Usage:writeq(Term)

Behaves like current_output(S), writeq(S,Term).

Reexported from write.

ISO

Usage:write_canonical(Stream,Term)

Behaves like write_term(Stream, Term, [quoted(true), ignore_ops(true)]). The output of this predicate can always be parsed by read_term/2 even if the term contains special characters or if operator declarations have changed.

Reexported from write.

ISO

Usage:write_canonical(Term)

Behaves like current_output(S), write_canonical(S,Term).

Reexported from write.

PREDICATEprint/2

Usage:print(Stream,Term)

Behaves like write_term(Stream, Term, [numbervars(true), portrayed(true)]).

Reexported from write.

PREDICATEprint/1

Usage:print(Term)

Behaves like current_output(S), print(S,Term).

Reexported from write.

PREDICATEprintq/2

Usage:printq(Stream,Term)

Behaves like write_term(Stream, Term, [quoted(true), numbervars(true), portrayed(true)]).

Reexported from write.

PREDICATEprintq/1

Usage:printq(Term)

Behaves like current_output(S), printq(S,Term).

Reexported from write.

Usage:portray_clause(Stream,Clause)

Outputs the clause Clause onto Stream, pretty printing its variables and using indentation, including a period at the end. This predicate is used by listing/0.

Reexported from write.

Usage:portray_clause(Clause)

Behaves like current_output(S), portray_clause(S,Term).

Reexported from write.

PREDICATEnumbervars/3

Usage:numbervars(Term,N,M)

Unifies each of the variables in term Term with a term of the form '$VAR'(I) where I is an integer from N onwards. M is unified with the last integer used plus 1. If the resulting term is output with a write option numbervars(true), in the place of the variables in the original term will be printed a variable name consisting of a capital letter possibly followed by an integer. When N is 0 you will get the variable names A, B, ..., Z, A1, B1, etc.

Reexported from write.

PREDICATEprettyvars/1

Usage:prettyvars(Term)

Similar to numbervars(Term,0,_), except that singleton variables in Term are unified with '$VAR'('_'), so that when the resulting term is output with a write option numbervars(true), in the place of singleton variables _ is written. This predicate is used by portray_clause/2.

Reexported from write.

Usage:printable_char(Char)

Char is the code of a character which can be printed.

Reexported from write.

Reexported from write.

Reexported from write.

PREDICATEchar_code/2
ISOchar_code(Char,Code)

Reexported from iso_char.

PREDICATEatom_chars/2
ISOatom_chars(Atom,Chars)

Reexported from iso_char.

ISOnumber_chars(Number,Chars)

Reexported from iso_char.

PREDICATEchar_codes/2

Reexported from iso_char.

PREDICATEget_char/1

Reexported from iso_char.

PREDICATEget_char/2
ISOget_char(Stream,Char)

Reexported from iso_char.

PREDICATEpeek_char/1
ISO

Usage:

Similar to peek_code/1, but using char instead of code.

Reexported from iso_char.

PREDICATEpeek_char/2
ISO

Usage:

Similar to peek_code/2, but using char instead of code.

Reexported from iso_char.

PREDICATEput_char/1
ISO

Usage:

Similar to put_code/1, but using char instead of code.

Reexported from iso_char.

PREDICATEput_char/2
ISO

Usage:

Similar to put_code/2, but using char instead of code.

Reexported from iso_char.

PREDICATEonce/1
ISOonce(G)

Reexported from iso_misc.

PREDICATEforall/2
forall(Generate,Test)

Reexported from iso_misc.

PREDICATEcall_det/2
call_det(G,Det)

Reexported from iso_misc.

PREDICATEcompound/1
ISOcompound(T)

Reexported from iso_misc.

PREDICATEsub_atom/5
ISOsub_atom(Atom,Before,Length,After,Sub_atom)

Reexported from iso_misc.

ISOunify_with_occurs_check(X,Y)

Reexported from iso_misc.

PREDICATEformat/2

Usage:format(Format,Arguments)

Print Arguments onto current output stream according to format Format.

Reexported from format.

PREDICATEformat/3

Usage:format(Stream,Format,Arguments)

Print Arguments onto Stream according to format Format.

Reexported from format.

PREDICATEsformat/3

Usage:sformat(String,Format,Arguments)

Same as Format, Arguments, String)">format_to_string(Format, Arguments, String) (note the different argument order).

Reexported from format.

Usage:format_to_string(Format,Arguments,String)

Print Arguments onto current string String according to format Format. This predicate is similar to the format/2, but the result is stored in a string.

Reexported from format.

Usage:format_control(C)

C is an atom or string describing how the arguments should be formatted. If it is an atom it will be converted into a string with name/2.

Reexported from format.

PREDICATEsort/2
sort(List1,List2)

Usage:

List2 is the sorted list corresponding to List1.

Reexported from sort.

PREDICATEkeysort/2
keysort(List1,List2)

Usage:

List2 is the (key-)sorted list corresponding to List1.

Reexported from sort.

REGTYPEkeylist/1

Usage:keylist(L)

L is a list of pairs of the form Key-Value.

Reexported from sort.

REGTYPEkeypair/1

Usage:keypair(P)

P is a pair of the form "K-_", where K is considered the key.

Reexported from sort.

PREDICATEbetween/3

Usage:between(Min,Max,N)

N is a number which is greater than or equal to Min and smaller than or equal to Max. Both Min and Max can be either integer or real numbers.

Reexported from between.

PREDICATEnow/1
now(Time)

Reexported from system.

PREDICATEdatime/1
datime(Datime)

Reexported from system.

Reexported from system.

PREDICATEdatime/9
datime(Time,Year,Month,Day,Hour,Min,Sec,WeekDay,YearDay)

Usage 1:

If Time is given, the rest of the arguments are unified with the date and time to which the Time argument refers.

Usage 2:

Bound Time, WeekDay and YearDay as determined by the input arguments.

Usage 3:

Bound Time to current time and the rest of the arguments refer to current time.

Reexported from system.

Usage:copy_option(Opt)

Opt is a file copy option.

copy_option(overwrite).
copy_option(timestamp).
copy_option(symlink).
copy_option(append).

Reexported from system.

Usage:copy_options(Opts)

Opts is a list of file copy options.

Reexported from system.

PREDICATEcopy_file/2
copy_file(Source,Destination)

Reexported from system.

PREDICATEcopy_file/3

Reexported from system.

PREDICATEgetenvstr/2
getenvstr(Name,Value)

Reexported from system.

PREDICATEsetenvstr/2
setenvstr(Name,Value)

Reexported from system.

PREDICATEset_env/2
set_env(Name,Value)

Reexported from system.

PREDICATEdel_env/1
del_env(Name)

Reexported from system.

PREDICATEcurrent_env/2
current_env(Name,Value)

Reexported from system.

extract_paths(PathList,Paths)

Reexported from system.

current_host(Hostname)

Reexported from system.

current_executable(Path)

Reexported from system.

PREDICATEumask/2

Usage 1:umask(OldMask,NewMask)

The process file creation mask was OldMask, and it is changed to NewMask.

Usage 2:umask(OldMask,NewMask)

Gets the process file creation mask without changing it.

Reexported from system.

working_directory(OldDir,NewDir)

Usage 1:

Changes current working directory.

Usage 2:working_directory(OldDir,NewDir)

Gets current working directory.

Reexported from system.

PREDICATEcd/1
cd(Path)

Reexported from system.

directory_files(Directory,FileList)

Reexported from system.

PREDICATEmktemp/2
mktemp(Template,Filename)

Reexported from system.

Reexported from system.

PREDICATEfile_exists/1
file_exists(File)

Reexported from system.

PREDICATEfile_exists/2
file_exists(File,Mode)

Reexported from system.

file_property(File,Property)

Reexported from system.

file_properties(Path,Type,Linkto,Time,Protection,Size)

Reexported from system.

PREDICATEmodif_time/2
modif_time(File,Time)

Reexported from system.

PREDICATEmodif_time0/2
modif_time0(File,Time)

Reexported from system.

modif_time_us(File,Time)

Reexported from system.

modif_time0_us(File,Time)

Reexported from system.

PREDICATEtouch/1
touch(File)

Reexported from system.

PREDICATEfmode/2
fmode(File,Mode)

Reexported from system.

PREDICATEchmod/2
chmod(File,NewMode)

Reexported from system.

PREDICATEchmod/3
chmod(File,OldMode,NewMode)

Usage 2:chmod(File,OldMode,NewMode)

If OldMode is identical to NewMode then it is equivalent to fmode(File,OldMode)

Reexported from system.

set_exec_mode(SourceName,ExecName)

Reexported from system.

delete_directory(File)

Reexported from system.

PREDICATEdelete_file/1
delete_file(File)

Reexported from system.

PREDICATErename_file/2
rename_file(File1,File2)

Reexported from system.

make_directory(DirName,Mode)

Reexported from system.

make_directory(DirName)

Reexported from system.

PREDICATEmkpath/2
mkpath(Path,Mode)

Reexported from system.

PREDICATEmkpath/1
mkpath(Path)

Reexported from system.

Usage:system_error_report(Report)

Report is the error message from the last system call, like strerror in POSIX.

Reexported from system.

PREDICATEget_tmp_dir/1

Usage:get_tmp_dir(TmpDir)

TmpDir is the (normalized) temporary directory for scratch space. On POSIX systems it is computed from normalizing the path specified in the TMPDIR environment variable. On Windows it is determined by the TMP or TEMP environment variable. If none is defined, this predicate tries to guess it from some usual locations (/tmp, /var/tmp, /usr/tmp on POSIX, c:\temp, c:\tmp, \temp, \tmp on Windows) or use . as last resort.

Reexported from system.

PREDICATEdev_null/1

Usage:dev_null(Path)

File path for the null device (/dev/null file in POSIX, nul in Windows)

Reexported from system.

PREDICATEpause/1
pause(Seconds)

Reexported from system.

PREDICATEwait/2

Usage:wait(Pid,RetCode)

wait/2 waits for the process numbered Pid. Fails if the process does not terminate normally or in case of error (see C waitpid() for details). RetCode is a positive number indicating the process return code if the process terminated normally, or a negative number if the process terminated due to a signal.

Reexported from system.

PREDICATEkill/2

Usage:kill(Pid,Signal)

kill/2 sends the signal Signal to the process or process group specified by Pid. See Unix man page for a detailed description of signals.

Reexported from system.

PREDICATEget_pid/1
get_pid(Pid)

Reexported from system.

PREDICATEget_uid/1
get_uid(Uid)

Reexported from system.

PREDICATEget_gid/1
get_gid(Uid)

Reexported from system.

PREDICATEget_pwnam/1
get_pwnam(User)

Reexported from system.

PREDICATEget_grnam/1
get_grnam(Group)

Reexported from system.

get_numcores(N)

Reexported from system.

PREDICATEshell/0

Usage:

Executes the OS-specific system shell. When the shell process terminates, control is returned to Prolog. See shell/2 for details.

Reexported from system.

PREDICATEshell/1
shell(Command)

Reexported from system.

PREDICATEshell/2
shell(Command,RetCode)

Reexported from system.

PREDICATEsystem/1
system(Command)

Reexported from system.

PREDICATEsystem/2
system(Command,RetCode)

Reexported from system.

PREDICATEfd_dup/2
fd_dup(FD,NewFD)

Usage 1:

Duplicate a file description into a new free file descriptor (C dup())

Usage 2:

Duplicate a file description into a specified file descriptor (C dup2())

Reexported from system.

PREDICATEfd_close/1

Usage:

Close the file descriptor (using C close())

Reexported from system.

PREDICATEwinpath/3
winpath(Option,Posix,WinPath)

Reexported from system.

PREDICATEwinpath/2

Reexported from system.

PREDICATEwinpath_c/3

Reexported from system.

PREDICATEcyg2win/3

Usage:cyg2win(CygWinPath,WindowsPath,SwapSlash)

Converts a posix path to a Windows-style path. If SwapSlash is swap, slashes are converted in to backslash. If it is noswap, they are preserved.

Reexported from system.

Reexported from system.

PREDICATEcyg2win_a/3

Reexported from system.

Usage:

Using the Windows native API (not POSIX)

Reexported from system.

PREDICATEget_home/1

Usage:get_home(H)

H is the home directory (HOME environment variable in POSIX systems and APPDATA in Windows)

Reexported from system.

Usage:find_executable(Name,Path)

Path is the path of the command Name: Name itself if it has a directory part, otherwise the first match in the PATH (environment variable) directories (never the current directory). A match is an executable file that is not a directory (any existing file in Windows). The suffix for executable files is optionally added to Path depending on the current operating system.

Reexported from system.

PREDICATEsee/1

Reexported from dec10_io.

PREDICATEseeing/1

Reexported from dec10_io.

PREDICATEseen/0

Reexported from dec10_io.

PREDICATEtell/1

Reexported from dec10_io.

PREDICATEtelling/1

Reexported from dec10_io.

PREDICATEtold/0

Reexported from dec10_io.

PREDICATEclose_file/1

Reexported from dec10_io.

PREDICATErecorda/3
recorda(Key,Term,Ref)

Reexported from old_database.

PREDICATErecordz/3
recordz(Key,Term,Ref)

Reexported from old_database.

PREDICATErecorded/3
recorded(Key,Term,Ref)

Reexported from old_database.

PREDICATEcurrent_key/2
current_key(KeyName,KeyTerm)

Reexported from old_database.

PREDICATEttyget/1

Reexported from ttyout.

PREDICATEttyget1/1

Reexported from ttyout.

PREDICATEttynl/0

Reexported from ttyout.

PREDICATEttyput/1

Reexported from ttyout.

PREDICATEttyskip/1

Reexported from ttyout.

PREDICATEttytab/1

Reexported from ttyout.

PREDICATEttyflush/0

Reexported from ttyout.

PREDICATEttydisplay/1

Reexported from ttyout.

PREDICATEttydisplayq/1

Reexported from ttyout.

PREDICATEttyskipeol/0

Reexported from ttyout.

Reexported from ttyout.

Documentation on imports

This module has the following direct dependencies: