4 Built-in Predicates
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
      • Built-in Predicates
        • Notation of Predicate Descriptions
        • Character representation
        • Loading Prolog source files
        • Editor Interface
        • Verify Type of a Term
          • var/1
          • nonvar/1
          • integer/1
          • float/1
          • rational/1
          • rational/3
          • number/1
          • atom/1
          • blob/2
          • string/1
          • atomic/1
          • compound/1
          • callable/1
          • ground/1
          • cyclic_term/1
          • acyclic_term/1
        • Comparison and Unification of Terms
        • Control Predicates
        • Meta-Call Predicates
        • Delimited continuations
        • Exception handling
        • Printing messages
        • Handling signals
        • DCG Grammar rules
        • Database
        • Declaring predicate properties
        • Examining the program
        • Input and output
        • Status of streams
        • Primitive character I/O
        • Term reading and writing
        • Analysing and Constructing Terms
        • Analysing and Constructing Atoms
        • Localization (locale) support
        • Character properties
        • Operators
        • Character Conversion
        • Arithmetic
        • Misc arithmetic support predicates
        • Built-in list operations
        • Finding all Solutions to a Goal
        • Forall
        • Formatted Write
        • Global variables
        • Terminal Control
        • Operating System Interaction
        • File System Interaction
        • User Top-level Manipulation
        • Creating a Protocol of the User Interaction
        • Debugging and Tracing Programs
        • Debugging and declaring determinism
        • Obtaining Runtime Statistics
        • Execution profiling
        • Memory Management
        • Windows DDE interface
        • Miscellaneous
    • Packages

4.5 Verify Type of a Term

Type tests are semi-deterministic predicates that succeed if the argument satisfies the requested type. Type-test predicates have no error condition and do not instantiate their argument. See also library library(error).

[ISO]var(@Term)
True if Term currently is a free variable.
[ISO]nonvar(@Term)
True if Term currently is not a free variable.
[ISO]integer(@Term)
True if Term is bound to an integer.
[ISO]float(@Term)
True if Term is bound to a floating point number.
rational(@Term)
True if Term is bound to a rational number. Rational numbers include integers.
rational(@Term, -Numerator, -Denominator)
True if Term is a rational number with given Numerator and Denominator. The Numerator and Denominator are in canonical form, which means Denominator is a positive integer and there are no common divisors between Numerator and Denominator.
[ISO]number(@Term)
True if Term is bound to a rational number (including integers) or a floating point number.
[ISO]atom(@Term)
True if Term is bound to an atom.
blob(@Term, ?Type)
True if Term is a blob of type Type. See section 12.4.9.
string(@Term)
True if Term is bound to a string. Note that string here refers to the built-in atomic type string as described in section 5.2. Starting with versionĀ 7, the syntax for a string object is text between double quotes, such as "hello".63In traditional Prolog systems, double quoted text is often mapped to a list of character codes. See also the Prolog flag double_quotes.
[ISO]atomic(@Term)
True if Term is bound (i.e., not a variable) and is not compound. Thus, atomic acts as if defined by:
atomic(Term) :-
        nonvar(Term),
        \+ compound(Term).

SWI-Prolog defines the following atomic datatypes: atom (atom/1), string (string/1), integer (integer/1), floating point number (float/1) and blob (blob/2). In addition, the symbol [] (empty list) is atomic, but not an atom. See section 5.1.

[ISO]compound(@Term)
True if Term is bound to a compound term. See also functor/3 =../2, compound_name_arity/3 and compound_name_arguments/3.
[ISO]callable(@Term)
True if Term is bound to an atom or a compound term. This was intended as a type-test for arguments to call/1, call/2 etc. Note that callable only tests the surface term. Terms such as (22,true) are considered callable, but cause call/1 to raise a type error. Module-qualification of meta-argument (see meta_predicate/1) using :/2 causes callable to succeed on any meta-argument.64We think that callable/1 should be deprecated and there should be two new predicates, one performing a test for callable that is minimally module aware and possibly consistent with type-checking in call/1 and a second predicate that tests for atom or compound. Consider the program and query below:
:- meta_predicate p(0).

p(G) :- callable(G), call(G).

?- p(22).
ERROR: Type error: `callable' expected, found `22'
ERROR: In:
ERROR:    [6] p(user:22)
[ISO]ground(@Term)
True if Term holds no free variables. See also nonground/2 and term_variables/2.
cyclic_term(@Term)
True if Term contains cycles, i.e. is an infinite term. See also acyclic_term/1 and section 2.17.65The predicates cyclic_term/1 and acyclic_term/1 are compatible with SICStus Prolog. Some Prolog systems supporting cyclic terms use is_cyclic/1 .
[ISO]acyclic_term(@Term)
True if Term does not contain cycles, i.e. can be processed recursively in finite time. See also cyclic_term/1 and section 2.17.