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

NextPrevUpTopContentsIndex

A.12 Built-in Predicates

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

  1. /== (?x ?y)

same as Prolog \==

  1. = (?x ?y)

standard Prolog

  1. =.. (?x ?y)

standard Prolog

  1. == (?x ?y)

standard Prolog

  1. @< (?x ?y)

same as Prolog except all variables sort as identical

  1. @=< (?x ?y)

ditto

  1. @> (?x ?y)

ditto

  1. @>= (?x ?y)

ditto

  1. append (?x ?y ?z)

standard Prolog

  1. arg (+index +term ?value)

standard Prolog

  1. asserta (+exp)

standard Prolog

  1. assertz (+exp)

standard Prolog

  1. atomic (?x)

standard Prolog

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

standard Prolog (unusual syntax)*

  1. call (+exp)

standard Prolog

  1. clause (+head ?tail)

standard Prolog

  1. debug ()

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

  1. debugging ()

display a list of all spied goals

  1. defdetrel
  2. (+name &rest +clauses)

define a relation and declare it to be deterministic

  1. defgrammar
  2. (+name &rest +rules)

define a grammar rule

  1. defrel
  2. (+name &rest +clauses)

define a relation

  1. defrelmacro
  2. (+name +args &rest +body)

define a logic macro

  1. defrel-special-form-macro
  2. (+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.

  1. deterministic (+name)

declare the relation called ?name to be deterministic

  1. erase (+ref)

delete the predicate with database reference ?ref from the database

  1. fail ()

standard Prolog

  1. findall
  2. (?exp +goal ?result)

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

  1. findallset
  2. (?exp +goal ?result)

same as findall/3 but removes duplicates

  1. functor
  2. (?term ?functor ?arity)

standard Prolog

  1. halt ()

exit Common Prolog

  1. integer (?x)

standard Prolog

  1. is (?result +exp)

standard Prolog

  1. keysort (+in ?out)

standard Prolog except uses alist style cons pairs

  1. 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 fail), or a list of ports.

  1. listing
  2. (+name &optional +arity)

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

  1. member (?x ?y)

standard Prolog

  1. nodebug ()

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

  1. nonvar (?x)

standard Prolog

  1. 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

  1. not (+x)

standard Prolog

  1. notrace ()

turn off exhaustive tracing for debugged goals

  1. 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

  1. output-defrels
  2. (+name ?defrels)

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

  1. read-term (?term)

read in a term

  1. recorda (+exp ?val ?ref)

standard Prolog

  1. recorded (+term ?val ?ref)

standard Prolog

  1. recordz (+exp ?val ?ref)

standard Prolog

  1. repeat ()

standard Prolog

  1. retract (+clause)

standard Prolog

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

standard Prolog (unusual syntax)*

  1. sort (+in ?out)

standard Prolog

  1. 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.

  1. trace ()

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

  1. translate-vars
  2. (?intern ?extern)

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

  1. true ()

standard Prolog

  1. 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.

  1. var (?x)

standard Prolog

* 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 (Windows version) - 26 Feb 2015

NextPrevUpTopContentsIndex