Miscellaneous Builtin Predicate Set

In the examples below, assume the database contains

?- dynamic(test/1).
?- public(test/2).

test(1).
test(1).	% Note that this is asserted twice
test(2) :- atom(a).
test(3).

test(a, b).
test(a, c).

Also, assume that the standard input stream will yield the following when read (where <space> stands for a single space).

<space>a(b, C).
/* This is a comment */ abc.

Also, assume that there exists a text input stream with alias textin, a text output stream with alias textout, and a binary output stream with alias binaryout. Assume that the the first line of textin contains

<space>x(y, Z).

 

abort / 0
Prototype: abort
Aborts execution. In the interpreter, causes control to return to top level; in compiled code, forces an error exit.
Example: abort - aborts execution.
 
break / 0
Prototype: break
Initiates a new interpreter loop, which continues to run until terminated by end-of-file, at which point the original code that was executing when break resumes.
Example: break - initiates a break loop.
 
deny / 1
Prototype: deny(PredicateIndicator)
Removes all clauses for a user predicate written in Prolog, leaving the predicate itself intact.
Example: deny(test/1) - removes all clauses of arity 1 having the functor test.
 
foreach / 2
Prototype: foreach(GoalA, GoalB)
Calls/redoes GoalA repeatedly and, for each success, calls GoalB once. Succeeds if GoalB succeeds for every successof GoalA. Opaque to cuts occurring either in GoalA or GoalB. (Often used as a form of looping construct.)
Example: foreach(test(X), write(X)) - writes 1123.
 
peek / 1
Prototype: peek(Code)
(Same as ISO peek_code/1) Unify Code with the code for the character that would be accessed by get0/1, without actually extracting the character from the input stream.
Example: peek(C) - instantiates C to 32 (the code for space).
 
peek / 2
Prototype: peek(StreamOrAlias, Code)
(Same as ISO peek_code/2) Unify Code with the code for the character that would be accessed by get0/2 on the same stream, without actually extracting the character from the input stream.
Example: peek(textin, C) - instantiates C to 32 (the code for space).
 
read_line / 1
Prototype: read_line(Line)
Unifies Line with the unread portion of the current line in the current input stream. (Reads a new line if at end-of-line.)
Example: read_line(Line) - instantiates Line to '<space>a(b, C).'
 
read_line / 2
Prototype: read_line(StreamOrAlias Line)
Unifies Line with the unread portion of the current line in the stream / stream whose alias is StreamOrAlias. (Reads a new line if at end-of-line.)
Example: read_line(textin, Line) - instantiates Line to '<space>x(y, Z).'
 
reset / 1
Prototype: reset(StreamOrAlias)
Resets input stream / stream having alias StreamOrAlias to be not at end. If StreamOrAlias refers to a file reading starts from the beginning again on subsequent operations.
Example: reset(textin) - resets stream textin.
 
skipln / 0
Prototype: skipln
Skips forward in the current input stream past the end of the current line. The next get type operation will get the character at the start of the next line.
Example: skipln - skips forward in the current input stream, so the next character read in the example stream would be '/'.
 
skipln / 1
Prototype: skipln(StreamOrAlias)
Skips forward in the stream / stream having the alias StreamOrAlias past the end of the current line. The next get type operation will get the character at the start of the next line.
Example: skipln(textin) - skips forward in textin, so that the stream is at end of file.
 
stream / 1
Prototype: stream(Term)
Succeeds if Term is a number
Example: stream_property(S, [alias(textin)]), stream(S) - succeeds.
Example: stream(1) - fails.
Example: stream(a(b)) - fails.
Example: stream(A) - fails.
 
throw_error / 1
Prototype: throw_error(Error)
Rethrow an error. Error must be the second argument of a ball of the form error(_, Error) caught by catch/3.
Example: throw_error(E) - (Assume catch/3 caught a ball of the form error(_, E) ) rethrows the error that was caught