All Manuals > KnowledgeWorks and Prolog User Guide > Appendix A: Common Prolog

A.12 Built-in Predicates

The built-in predicates listed in the table below are exported from the common-prolog (clog) package.

/== (?x ?y)

same as Prolog \==

= (?x ?y)

standard Prolog

=.. (?x ?y)

standard Prolog

== (?x ?y)

standard Prolog

@< (?x ?y)

same as Prolog except all variables sort as identical

@=< (?x ?y)

ditto

@> (?x ?y)

ditto

@>= (?x ?y)

ditto

append (?x ?y ?z)

standard Prolog

arg (+index +term ?value)

standard Prolog

asserta (+exp)

standard Prolog

assertz (+exp)

standard Prolog

atomic (?x)

standard Prolog

bagof (?exp
(+goal . +ex-vars)
?bag)

standard Prolog (unusual syntax)*

call (+exp)

standard Prolog

clause (+head ?tail)

standard Prolog

debug ()

cause debugging information to be saved for each call whether it is spied or not

debugging ()

display a list of all spied goals

defdetrel
(+name &rest +clauses)

define a relation and declare it to be deterministic

defgrammar
(+name &rest +rules)

define a grammar rule

defrel
(+name &rest +clauses)

define a relation

defrelmacro
(+name +args &rest +body)

define a logic macro

defrel-special-form-macro
(+name +args &rest +body)

like defrelmacro but can have &rest in +args. Use of this form will shadow all predicates named +name regardless of arity.

deterministic (+name)

declare the relation called ?name to be deterministic

erase (+ref)

delete the predicate with database reference ?ref from the database

fail ()

standard Prolog

findall
(?exp +goal ?result)

generate all solutions to ?goal and instantiate ?exp with the values. Return a list in ?result.

findallset
(?exp +goal ?result)

same as findall/3 but removes duplicates

functor
(?term ?functor ?arity)

standard Prolog

halt ()

exit Common Prolog

integer (?x)

standard Prolog

is (?result +exp)

standard Prolog

keysort (+in ?out)

standard Prolog except uses alist style cons pairs

leash (+event-spec)

cause the interpreter to pause and ask for input when one of the leashed events is traced. An event-spec is one of: call, exit, redo or fail, or a list of ports.

listing
(+name &optional +arity)

display a listing of the named predicate or listings for each arity if no arity is specified

member (?x ?y)

standard Prolog

nodebug ()

leave debug mode (cease saving debug info for non-spied goals)

nonvar (?x)

standard Prolog

nospy (+args)

remove +args from the list of spied goals. +args may be a predicate name or a list of predicate names. Unspy all goals if +args is nil

not (+x)

standard Prolog

notrace ()

turn off exhaustive tracing for debugged goals

once (+exp)

satisfy +exp as a goal once, then fail on retrying even if +exp has more solutions: this can be used to make a call deterministic so that the compiler can perform last call optimization

output-defrels
(+name ?defrels)

return a list of defrel expressions derived from the dynamic clauses associated with ?name

read-term (?term)

read in a term

recorda (+exp ?val ?ref)

standard Prolog

recorded (+term ?val ?ref)

standard Prolog

recordz (+exp ?val ?ref)

standard Prolog

repeat ()

standard Prolog

retract (+clause)

standard Prolog

setof (?exp
(+goal . +ex-vars)
?bag)

standard Prolog (unusual syntax)*

sort (+in ?out)

standard Prolog

spy (+args)

spy +args. +args may be a predicate name or a list of predicate names. If arity is not mentioned for a predicate name, predicates of all arities with that name are spied.

trace ()

turn on tracing for debugged goals, also turn on debugging for the next top level goal

translate-vars
(?intern ?extern)

translate back and forth between internal and external variable representations. Can be used to pretty up the writing of terms containing variables

true ()

standard Prolog

unleash (+event-spec)

Undo leashing for +event-spec. +event-spec may be a port or a list of ports. If +event-spec is nil, all ports are unleashed.

var (?x)

standard Prolog

phrase +exp ?list

standard Prolog way to call a grammar rule

phrase +exp ?list ?tail

standard Prolog way to call a grammar rule

* setof and bagof in standard Prolog use a special syntax for existentially quantified variables, for example:

?- setof(X, Y^foo(X,Y), Z).

In Common Prolog, this would look like:

==> (setof ?x ((foo ?x ?y) ?y) ?z)

So, a goal with no existentially quantified variables is nested in an extra set of parentheses:

==> (bagof ?x ((bar ?x)) ?z)

KnowledgeWorks and Prolog User Guide (Macintosh version) - 01 Dec 2021 19:35:39