These predicates convert between Prolog constants and lists of character codes. The predicates atom_codes/2, number_codes/2 and name/2 behave the same when converting from a constant to a list of character codes. When converting the other way around, atom_codes/2 will generate an atom, number_codes/2 will generate a number or exception and name/2 will return a number if possible and an atom otherwise.
The ISO standard defines atom_chars/2 to describe the `broken-up' atom as a list of one-character atoms instead of a list of codes. Up-to version 3.2.x, SWI-Prolog's atom_chars/2 behaved, compatible to Quintus and SICStus Prolog, like atom_codes. As of 3.3.x SWI-Prolog atom_codes/2 and atom_chars/2 are compliant to the ISO standard.
To ease the pain of all variations in the Prolog community, all SWI-Prolog predicates behave as flexible as possible. This implies the `list-side' accepts either a code-list or a char-list and the `atom-side' accept all atomic types (atom, number and string).
?- atom_chars(hello, X). X = [h, e, l, l, o]
backcomp.pl
syntax_error
if Number is unbound and CharList
does not describe a number.name(N, "300"), 400 is N + 100
' succeeds).syntax_error
exception is raised. Otherwise Term is ``written'' on Atom
using write/1.variable_names
and return the read term in Term
and the variable bindings in Bindings. Bindings is
a list of
Name = Var couples, thus providing
access to the actual variable names. See also read_term/2.
If Atom has no valid syntax, a syntax_error
exception is raised.?- concat_atom([gnu, gnat], ', ', A). A = 'gnu, gnat'
This predicate can also be used to split atoms by instantiating Separator and Atom:
?- concat_atom(L, -, 'gnu-gnat'). L = [gnu, gnat]
[]
is both an atom an empty code/character list. The predicate atom_length/2
returns 2 for this atom.?- sub_atom(Atom, 0, _, _, Prefix)
.
Depreciated.?- sub_atom(abc, 1, 1, A, S). A = 1, S = b
The implementation minimises non-determinism and creation of atoms. This is a very flexible predicate that can do search, prefix- and suffix-matching, etc.