Scryer Prolog

Module iso_ext

:- use_module(library(iso_ext)).

Useful general predicates that are not ISO standard yet

Predicates available here are similar to the ones defined in builtin.pl, but they're not part of the ISO Prolog standard at the moment.

forall(Generate, Test).

For all bindings possible by Generate, Test must be true.

In this example, it checks that all numbers are even:


?- Ns = [2,4,6], forall(member(N, Ns), 0 is N mod 2).
   Ns = [2,4,6].

bb_put(+Key, +Value).

Sets a global variable named Key (must be an atom) with value Value. The global variable isn't backtrackable. Check bb_b_put/2 for the backtrackable version.


?- bb_put(city, "Valladolid").
   true.
?- bb_get(city, X).
   X = "Valladolid".

In this example one can understand the difference between bb_put/2 and bb_b_put/2:


?- bb_put(city, "Valladolid"), (bb_put(city, "Salamanca"), false);(bb_get(city, X)).
   X = "Salamanca".
?- bb_put(city, "Valladolid"), (bb_b_put(city, "Salamanca"), false);(bb_get(city, X)).
   X = "Valladolid".

bb_b_put(+Key, +Value).

Sets a global variable named Key (must be an atom) with value Value. The global variable is backtrackable. Check bb_put/2 for the non-backtrackable version.


?- bb_b_put(city, "Valladolid").
   true.
?- bb_get(city, X).
   X = "Valladolid".

In this example one can understand the difference between bb_put/2 and bb_b_put/2:


?- bb_put(city, "Valladolid"), (bb_put(city, "Salamanca"), false);(bb_get(city, X)).
   X = "Salamanca".
?- bb_put(city, "Valladolid"), (bb_b_put(city, "Salamanca"), false);(bb_get(city, X)).
   X = "Valladolid".

bb_get(+Key, -Value).

Gets the value Value of a global variable named Key (must be an atom)

succ(?I, ?S).

True iff S is the successor of the non-negative integer I. At least one of the arguments must be instantiated.

call_cleanup(Goal, Cleanup).

Executes Goal and then, either on success or failure, executes Cleanup. The success or failure of Cleanup is ignored and choice points created inside are destroyed.

setup_call_cleanup(Setup, Goal, Cleanup).

If Setup succeeds, Cleanup will be called after the execution of Goal. Goal itself can succeed or not.

In this example, we use the predicate to always close an open file:


?- setup_call_cleanup(open(File, read, Stream), do_something_with_stream(Stream), close(Stream)).

call_with_inference_limit(Goal, Limit, Result).

Similar to call(Goal) but it limits the number of inferences for each solution of Goal. Calls to it may be nested, but only the last limit will be in power.

partial_string(String, L, L0)

Explicitly construct a partial string "manually". It can be used as an optimized append/3. It's not recommended to use this predicate in application code.

partial_string(+String)

Succeeds if String is a partial string. A partial string is a string composed of several smaller strings, even just one. That means all strings in Scryer are partial strings.

partial_string_tail(+String, -Tail).

Unifies Tail with the last section of the partial string. It's not recommended to use this predicate in application code.

call_nth(Goal, N).

Succeeds when Goal succeeded for the Nth time (there are at least N solutions)

countall(G_0, N).

countall(G0, N) is true iff N unifies with the total number of answers of call(G0).

copy_term_nat(Source, Dest)

Similar to copy_term/2 but without attribute variables

copy_term(+Term, -Copy, -Gs).

Produce a deep copy of Term and unify it to Copy, without attributes. Unify Gs with a list of goals that represent the attributes of Term. Similar to copy_term/2 but splitting the attributes.

call_residue_vars/2