next up previous
Next: Representing Text in Up: Built-In Predicates Previous: Analysing and Constructing

Analysing and Constructing Atoms

These predicates convert between Prolog constants and lists of ASCII values. The predicates atom_chars/2, number_chars/2 and number/2 behave the same when converting from a constant to a list of ASCII values. When converting the other way around, atom_chars/2 will generate an atom, number_chars will generate a number or fail and name/2 will return a number if possible and an atom otherwise.

atom_chars( ?Atom, ?String)

  Convert between an atom and a list of ASCII values. If Atom is instantiated, if will be translated into a list of ASCII values and the result is unified with String. If Atom is unbound and String is a list of ASCII values, it will Atom will be unified with an atom constructed from this list.
atom_char( ?Atom, ?ASCII)

  Convert between character and ASCII value for a single character.
number_chars( ?Number, ?String)

  Similar to atom_chars/2, but converts between a number and its representation as a list of ASCII values. Fails silently if Atom is unbound and String does not describe a number.
name( ?AtomOrInt, ?String)

  String is a list of ASCII values describing Atom. Each of the arguments may be a variable, but not both. When String is bound to an ASCII value list describing an integer and Atom is a variable Atom will be unified with the integer value described by String (e.g. `name(N, "300"), 400 is N + 100 ' succeeds).
int_to_atom( +Int, +Base, -Atom)

  Convert Int to an ascii representation using base Base and unify the result with Atom. If the base will be prepended to Atom. will try to interpret Int as an ASCII value and return 0'c. Otherwise . Some examples are given below.

int_to_atom( +Int, -Atom)

  Equivalent to int_to_atom(Int, 10, Atom).
term_to_atom( ?Term, ?Atom)

  Succeeds if Atom describes a term that unifies with Term. When Atom is instantiated Atom is converted and then unified with Term. Otherwise Term is ``written'' on Atom using write/1.
atom_to_term( +Atom, -Term, -Bindings)

  Use Atom as input to read_variables/2 and return the read term in Term and the variable bindings in Bindings. Bindings is a list of couples, thus providing access to the actual variable names. See also read_variables/2.
concat( ?Atom1, ?Atom2, ?Atom3)

  Atom3 forms the concatenation of Atom1 and Atom2. At least two of the arguments must be instantiated to atoms, intergers or floating point numbers.
concat_atom( +List, -Atom)

  List is a list of atoms, integers or floating point numbers. Succeeds if Atom can be unified with the concatenated elements of List. If List has exactly 2 elements it is equivalent to concat/3, allowing for variables in the list.
atom_length( +Atom, -Length)

  Succeeds if Atom is an atom of Length characters long. This predicate also works for integers and floats, expressing the number of characters output when given to write/1.



next up previous
Next: Representing Text in Up: Built-In Predicates Previous: Analysing and Constructing



Passani Luca
Tue Nov 14 08:58:33 MET 1995