Builtin predicates - Type testing

Predicates in this group take a term as an argument and succeed if the term has a certain type (atom, variable, integer, object, etc).

atom/1, atomic/1, class/1, class/2, compound/1, database/1, float/1, integer/1, nonvar/1, number/1, object/1, object/2, predicate/1, predicate/2, string/1, var/1


atom/1 - tests if a term is an atom.

Usage
atom(Term)
Description
If Term is an atom, then atom(Term) succeeds. Fails otherwise.
Examples
 atom(fred)           succeeds
 atom([])             succeeds
 atom(f(X))           fails
 atom(1.5)            fails
 atom("mary")         fails
Compatibility
Standard Prolog
See Also
atomic/1, compound/1, float/1, integer/1, number/1, string/1, var/1

atomic/1 - tests if a term is atomic.

Usage
atomic(Term)
Description
If Term is an atom, integer, floating-point number, or string, then atomic(Term) succeeds. Fails otherwise.
Examples
 atomic(fred)         succeeds
 atomic([])           succeeds
 atomic(f(X))         fails
 atomic(1.5)          succeeds
 atomic("mary")       succeeds
Compatibility
Standard Prolog, with the addition that strings are also considered atomic.
See Also
atom/1, float/1, integer/1, number/1, string/1, var/1

class/1 - tests if a term is a class object or name.

Usage
class(Term)
Description
If Term is a class object or an atom that names a class, then class(Term) succeeds. Fails otherwise.
Examples
 class person { ... }
 new person (P)

 class(person)        succeeds
 class(people)        fails (assuming 'people' is not a class)
 class(1.5)           fails
 class(f(X))          fails
 class(P)             fails
 class(P.prototype)   succeeds (P's prototype is the person class)
 class("person")      fails
See Also
class/2, object/1, predicate/1

class/2 - tests if a class name is associated with a specific class object.

Usage
class(Name, Class)
Description
If Name is an atom that names a class, then Class is unified with the class object corresponding to Name. Otherwise, if Class is a class object, then Name is unified with the name of Class. Fails in all other cases.
This predicate is typically used to retrieve the class object for a specific class name. The name of a class object can also be retrieved with Class.className.
Examples
 class person { ... }
 new person (P)

 class(person, C)         succeeds
 class(people, C)         fails
 class(1.5, C)            fails
 class(P, C)              fails
 class(P.className, C)    succeeds
 class(Name, P.prototype) succeeds
See Also
class/1, object/1, predicate/1

compound/1 - tests if a term is a compound functor or list.

Usage
compound(Term)
Description
If Term is a compound functor or list term, then compound(Term) succeeds. Fails otherwise. Lists are considered functors with the name "./2".
Examples
 compound(fred)       fails
 compound([])         fails
 compound(f(X))       succeeds
 compound([a])        succeeds
 compound(1.5)        fails
 compound("mary")     fails
Compatibility
Standard Prolog
See Also
atom/1, var/1

database/1 - tests if a term is a local predicate database.

Usage
database(Term)
Description
If Term is a local predicate database, then database(Term) succeeds. Fails otherwise.
Examples
 new_database(DB); database(DB)       succeeds
See Also
new_database/1

float/1 - tests if a term is a floating-point number.

Usage
float(Term)
Description
If Term is a floating-point number, then float(Term) succeeds. Fails otherwise.
Examples
 float(fred)          fails
 float(f(X))          fails
 float(1.5)           succeeds
 float(2)             fails
 float("mary")        fails
Compatibility
Standard Prolog
See Also
atom/1, integer/1, number/1, var/1

integer/1 - tests if a term is an integer number.

Usage
integer(Term)
Description
If Term is an integer number, then integer(Term) succeeds. Fails otherwise.
Examples
 integer(fred)        fails
 integer(f(X))        fails
 integer(1.5)         fails
 integer(2)           succeeds
 integer("mary")      fails
Compatibility
Standard Prolog
See Also
atom/1, float/1, number/1, var/1

nonvar/1 - tests if a term is not an unbound variable.

Usage
nonvar(Term)
Description
If Term is an unbound variable, then nonvar(Term) fails. Otherwise nonvar(Term) succeeds with no modification to Term.
Examples
 nonvar(X)            fails if X is unbound
 nonvar(fred)         succeeds
 nonvar(f(X))         succeeds
 nonvar(1.5)          succeeds
 nonvar("mary")       succeeds
Compatibility
Standard Prolog
See Also
atom/1, compound/1, var/1

number/1 - tests if a term is an integer or floating-point number.

Usage
number(Term)
Description
If Term is an integer or floating-point number, then number(Term) succeeds. Fails otherwise.
Examples
 number(fred)         fails
 number(f(X))         fails
 number(1.5)          succeeds
 number(2)            succeeds
 number("mary")       fails
Compatibility
Standard Prolog
See Also
atom/1, float/1, integer/1, var/1

object/1 - tests if a term is an instance object.

Usage
object(Term)
Description
If Term is an instance object, then object(Term) succeeds. Fails otherwise.
Examples
 class person { ... }
 new person (P)

 object(P)            succeeds
 object(person)       fails
 object(1.5)          fails
 object(f(X))         fails
 object(P.prototype)  fails (P's prototype is the person class)
 object("person")     fails
See Also
class/1, object/2, predicate/1

object/2 - tests if a term is an object that is an instance of a specific class.

Usage
object(Term, Class)
Description
If Term is an object that is an instance of Class or one of its subclasses, then object(Term, Class) succeeds. Fails otherwise. The Class may be a class object or an atom that names a class.
Examples
 class person { ... }
 new person (P)

 object(P, person)            succeeds
 object(P, people)            fails
 object(P, P)                 fails
 object(1.5, person)          fails
 object(f(X), person)         fails
 object(P, 1.5)               fails
 object(P.prototype, person)  fails
 object(P, "person")          fails
See Also
class/1, object/1, predicate/1

predicate/1 - tests if a term is a predicate.

Usage
predicate(Term)
Description
If Term is a predicate, then succeeds. Fails otherwise.
Examples
 foo(X, Y) { ... }
 predicate(P, foo/2);

 predicate(P)             succeeds
 predicate(a)             fails
 predicate(X)             fails
 predicate(foo(X, Y))     fails
 predicate(foo/2)         fails
 predicate(1.5)           fails
See Also
class/1, object/1, predicate/2

predicate/2 - tests if a term is a predicate with a specific name.

Usage
predicate(Term, Pred)
Description
If Term is a predicate, then Pred is unified with its predicate indicator. The indicator will have the form Name / Arity.
If Term is a variable and Pred has the form Name / Arity, then Term is unified with the predicate corresponding to Pred. Fails if Pred does not exist.
Errors
Examples
 foo(X, Y) { ... }

 predicate(Term, foo/2)
      succeeds with Term set to the predicate foo/2
 predicate(Term, Pred)
      succeeds with Pred = foo/2 if Term is the predicate foo/2
 predicate(Term2, person::age/1)
      sets Term2 to the method age/1 within the person class.
      Note: the single argument is the "Self" pointer.
See Also
class/1, object/1, predicate/1

string/1 - tests if a term is a string.

Usage
string(Term)
Description
If Term is a string, string(Term) succeeds. Fails otherwise.
Examples
 string(fred)         fails
 string(f(X))         fails
 string(1.5)          fails
 string(2)            fails
 string("mary")       succeeds
See Also
atom/1, compound/1, var/1

var/1 - tests if a term is an unbound variable.

Usage
var(Term)
Description
If Term is an unbound variable, then var(Term) succeeds with no modification to Term. Fails otherwise.
Examples
 var(X)               succeeds if X is unbound
 var(fred)            fails
 var(f(X))            fails
 var(1.5)             fails
 var("mary")          fails
Compatibility
Standard Prolog
See Also
atom/1, compound/1, nonvar/1

Generated on 26 May 2011 for plang by  doxygen 1.6.1